I'm using nodeJs to obtain a value in a redis key field. Something like this:
let result = await redisM.hget('aaa:bbb', 'profiles');
The value I'm looking for is an object but I keep getting "WRONGTYPE Operation against a key holding the wrong kind of value" exception and I if print the error from the hget method I get:
------------------------------------
{ ReplyError: WRONGTYPE Operation against a key holding the wrong kind of value
at parseError (/PATH123/node_modules/redis-parser/lib/parser.js:193:12)
at parseType (/PATH123/node_modules/redis-parser/lib/parser.js:303:14)
command: 'HGET',
args: [ 'aaa:bbb', 'profiles' ],
code: 'WRONGTYPE' }
------------------------------------
If I flush redis db, run the HGET aaa:bbb profiles
in redis-cli I get (nil)
result but that is not supposed to be throwing this error, or is it?
Also, if I set a value to that key via redis-cli I can get it's value using HGET afterwards:
HSET sip_profiles profiles {}
(integer) 1
HGET sip_profiles profiles
"{}"
Don't understand why it works with redis-cli but not with node... even with an empty key...
Node dependency used: "redis": "^2.8.0"
I got the same problem, I set up a String Key instead of a Hash key, then when I tried to retrieve the keys of the String key I got the error.
Solution: Ensure the desired key is Hash type, then the hget is not gonna fail