0

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?

Oops
  • 1,373
  • 3
  • 16
  • 46

1 Answers1

2

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>
Ankit Sahay
  • 1,710
  • 8
  • 14
  • Yes but this again gives me (error) WRONGTYPE Operation against a key holding the wrong kind of value. HSET 1000:123:1603872000 totalscore "100" uid "1000:123:1603872000" price "1000". But if I change key from 1000:123:1603872000 to 1000:123:160387200, no issues. TYPE 1000:123:1603872000 IS String and TYPE 1000:123:160387200 is hash – Oops Jan 05 '21 at 06:59
  • HSET 1000:123:1603872000 totalscore "100" uid "1000:123:1603872000" price "1000" This did not give any error. Can you show the exact command that you entered and the exact error messae? – Ankit Sahay Jan 05 '21 at 08:07
  • HSET 1000:123:1603872000 totalscore "100" uid "1000:123:1603872000" price "1000" same command : (error) WRONGTYPE Operation against a key holding the wrong kind of value – Oops Jan 05 '21 at 09:12
  • is this because of any redis version difference? If I remove the last 0 in the key , I get sucess. So that's why I checked both of its type. TYPE 1000:123:1603872000 is string and TYPE 1000:123:160387200 is hash. – Oops Jan 05 '21 at 09:14
  • 1
    Can you run HGETALL 1000:123:1603872000 and see what the result is? If there is an pre-existing data, tr removing the hasmap by running del 1000:123:1603872000 – Ankit Sahay Jan 05 '21 at 09:25