我正在使用 golang 玩 redis,但是当我尝试LPOP
从列表中获取一个元素时,我不断收到错误消息。它仅在我在列表中插入第一个元素时才有效,但是当我尝试添加第二个元素时,我不断收到以下错误:
WRONGTYPE Operation against a key holding the wrong kind of value
我已阅读文档,但我仍然收到此错误,请任何人指出我做错了什么,因为我仍在调试。谢谢
testCases := []struct{
name string
key string
val string
} {
{
name: "one",
key: "color",
val: "red",
},
{
name: "two"
key: "color",
val: "blue",
},
{
name: "three"
key: "color",
val: "purple",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T){
rc := redis.NewClient{} // params added
defer rc.Close()
err := rc.Send("RPUSH", tc.key, tc.val)
require.NoError(t, err)
err = rc.Flush()
require.NoError(t, err)
v, err = redis.String(rc.Do("LPOP", tc.key))
require.NoError(t, err)
assert.Exact(t, tc.val, v)
_, err = rc.Do("SETEX", tc.key, 10, tc.val)
require.NoError(t, err)
})
}