If stored value is type of list in hash field, HGETALL is returning the following response.
Reproduction steps below:
Connect to redis-cli, then:
HSET user1 user2user1 []
LPUSH user2user1 "test1"
LPUSH user2user1 "test2"
LRANGE user2user1 0 -1 #> shows ["test2", "test1"]
HGETALL user1 #> shows "user2user1" "[]"
I was expecting that HGETALL will return all array with all elements. I have checked the documentation but I could not find information on storing list with HSET.
Reference: https://redis.io/commands/hset/
2
Answers
HSET store key-value pairs.
You cannot link between keys.
You my want to look at RedisJSON module where you can store arrays.
You are using two different keys :
You are pushing on the list so the hash is unchanged.
Moreover, hash are used to store strings, there is no such thing as pushing as you can see in the documentation you provided. When you set
HSET user1 user2user1 []
you are setting the keyuser2user1
to the string[]
.It is not really a problem if
user2user1
is a unique string as it makes the hash useless in this "trivial" implementation.