how to use List on Redis developing with C++ using hiredis

591 views Asked by At

I try to use list with redis on Linux with C++ , how to use "rpush", "lpush", "rpop", "lpop" on C++? I wrote like these:

this->_reply = (redisReply *) redisCommand(this->_context, "LPUSH %s %s", key.c_str(), value.c_str());
this->_reply = (redisReply *) redisCommand(this->_context, "RPOP %s", key.c_str());

But it doesn't success, and the "this->_reply->str" said "WRONGTYPE Operation against a key holding the wrong kind of value"

How can I use these methods? Thanks

1

There are 1 answers

0
GuangshengZuo On

WRONGTYPE Operation against a key holding the wrong kind of value means the what the key hold is not a list, so when you want to do a lpush on this key, it complains about it.

You could use TYPE key command to test the key's type with redis-cli first.