0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

go-redisでSADDした時の挙動

Posted at
package main
  
import (
        "fmt"
        "time"
        "strconv"
        "github.com/go-redis/redis"
)

func getRedisClient() (*redis.Client) {
        client := redis.NewClient(&redis.Options{
                Addr:     "localhost:6379",
                Password: "", // no password set
                DB:       0,  // use default DB
        })
        return client
}

func main() {
        rc := getRedisClient()
        ts := strconv.Itoa(int(time.Now().Unix()))
        key := "set:"+ts
        ret := rc.SAdd(key, "hoge")
        fmt.Printf("ret1:%v,%v\n", ret.Err(), ret.Val())
        ret = rc.SAdd(key, "hoge")
        fmt.Printf("ret1:%v,%v\n", ret.Err(), ret.Val())
}
$ go run main.go
ret1:<nil>,1
ret1:<nil>,0
127.0.0.1:6379> smembers "set:1573302581"
1) "hoge"
  • 重複して入れようとしても特にエラーにはならない(当然ではありますが、、
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?