我需要从 Redis 队列执行一个简单的 lpop。 在 go lang 中,如果我使用 blpop 使用阻塞弹出,则 foll 代码有效
reply, err := redis.Strings(conn.Do("BLPOP", key, 1))
if err == nil {
fmt.Println(reply[1])
// do something with string reply[1]
}
但我不想阻止。我只需要在队列为空时结束。
那我该怎么做
如果我这样做 redis.Strings(conn.Do("LPOP", key))
即,将 BLPOP 更改为 LPOP,我得到一个 redigo 错误
ERROR = redigo: unexpected type for Strings, got type []uint8
最佳答案
我可以使用 redis.String() 获取 lpop 的值
这样就可以了
reply, err := redis.String(conn.Do("LPOP", key))
if err == nil {
fmt.Printf("REPLY= %s\n", reply)
//do something
关于go - 如何在golang中做Redis(redigo)lpop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52279988/