1
1
123 1232017-04-16 13:30:30
go
123 123, 2017-04-16 13:30:30

Am I using redis scan correctly? Or is the problem somewhere else?

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

When compiling this error:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x46f511]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2017-04-17
@JustFool

compile in pieces
something you obviously do not finish speaking

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question