WRONGTYPE Operation against a key holding the wrong kind of value php
Solution 1:
Redis supports 6 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>
- if value is of type stream -> xread count
<count>
streams<key>
<ID>
. https://redis.io/commands/xread
Use the TYPE
command to check the type of value a key is mapping to:
- type
<key>
Solution 2:
This error means that the value indexed by the key "l_messages" is not of type hash
, but rather something else. You've probably set it to that other value earlier in your code. Try various other value-getter commands, starting with GET, to see which one works and you'll know what type is actually here.