WRONGTYPE Operation against a key holding the wrong kind of value php

Trushar Narodia picture Trushar Narodia · Jun 21, 2016 · Viewed 113.7k times · Source

Hi I am using Laravel with Redis .When I am trying to access a key by get method then get following error "WRONGTYPE Operation against a key holding the wrong kind of value"

I am using following code to access the key value -

i use this code for get data from redis

$values = "l_messages";
$value = $redis->HGETALL($values);
print($value);

Answer

Phoebe Li picture Phoebe Li · Jun 8, 2017

Redis supports 5 data types. You need to know what type of value that a key maps to, as for each data type, the command to retrieve it is different.

Here are the commands to retrieve key value:

  • if value is of type string -> GET <key>
  • if value is of type hash -> HGETALL <key>
  • if value is of type lists -> lrange <key> <start> <end>
  • if value is of type sets -> smembers <key>
  • if value is of type sorted sets -> ZRANGEBYSCORE <key> <min> <max>

Use the TYPE command to check the type of value a key is mapping to:

  • type <key>