gogo-redis

go-redis library's SMembers method returning extra element in first position


I'm using the go-redis library v9, and wrote a simple test case using miniredis.

In a simple case, I use go-redis SAdd to add an item to a set, then use SMembers to get all the items back.

For some reason, SMembers is returning an extra numeric item in the beginning of the string slice.

added := redis.SAdd(ctx, "key1", "android_device2", expiration)
members := redis.SMembers(ctx, "key1").Val()
fmt.Printf("%v", members)

This prints [2592000000000000 android_device2], where could that first numeric element be coming from?


Solution

  • Take a look at the function signature, SAdd takes the context, the key, and then a list of members to add. You've added two members, the "android_device2" string, and whatever expiration is. When you pull the set members you're seeing those two.