Search code examples
redisredis-cli

Redis CLI - WRONGTYPE Operation against a key holding the wrong kind of value


I am new to redis. I am trying to execute the below command.

HSET 1000:123:1603872000 "totalscore":100 "uid":"1000:123:1603872000"  "price": 1000  "points": 30

But this gives me below error

(error) WRONGTYPE Operation against a key holding the wrong kind of value

type 1000:123:1603872000

This gives me type as string. How can I set string field values to a string key in redis?


Solution

  • The syntax for storing values in a hash map in redis is: hset hash_map_name key1 value1 key2 value2 key3 value3

    You don't have to separate key-value pair with a colon. In the example below I am storing 3 keys named as name, website and age in a hash map named _my_hash_map.

    127.0.0.1:6379> hset my_hash_map  name Ankit website StackOverflow age 100
    (integer) 3
    127.0.0.1:6379> hgetall my_hash_map
    1) "name"
    2) "Ankit"
    3) "website"
    4) "StackOverflow"
    5) "age"
    6) "100"
    127.0.0.1:6379>