1

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

wikios
  • 35
  • 1
  • 8
  • Perhaps you have previously added that same key to your redis instance as something other than a list ? – nos Aug 31 '17 at 07:59
  • @nos After I using "DEL key" to delete the key, run it again and have an Error said "terminate called after throwing an instance of 'std::logic_error' what():basic_string::_S_construct NULL not valid" what should I do next? – wikios Aug 31 '17 at 08:04
  • @Gerhardh sorry I forgot it and already deleted it – wikios Aug 31 '17 at 08:07
  • Next you need to post an [MCVE](https://stackoverflow.com/help/mcve) so people can debug and fix your code. – nos Aug 31 '17 at 09:15

1 Answers1

0

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.

GuangshengZuo
  • 4,447
  • 21
  • 27