Help us understand the problem. What is going on with this article?

go-redisのSMEMBERSの挙動

More than 1 year has passed since last update.
package main

import (
        "fmt"
        "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()
        //key := "sonzaisurukey"
                // ok
        key := "sonzaishinaikey"
                // ng

        v := rc.SMembers(key)
        fmt.Printf("v(%d):%v,%v\n", len(v.Val()), v.Err(), v.Val())

        if v.Err() != nil {
                fmt.Print("error is not nil\n")
        }
        if v.Err() == redis.Nil {
                fmt.Print("redis.Nil is coming\n")
        }
}
  • keyがあってもなくてもエラーにはならない。なくても要素数は0で返る。
adad
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away