redisClient.FlushDb()
for i := 0; i < 33; i++ {
err := redisClient.Set(fmt.Sprintf("key%d", i), "value", 0).Err()
if err != nil {
panic(err)
}
}
var cursor int64
var n int
for {
var keys []string
var err error
cursor, keys, err = redisClient.Scan(cursor, "", 10).Result()
if err != nil {
panic(err)
}
n += len(keys)
if cursor == 0 {
break
}
}
fmt.Printf("found %d keys\n", n)
// Output: found 33 keys
При компиляции такая ошибка:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x46f511]