skip to Main Content

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


  1. HSET store key-value pairs.
    You cannot link between keys.
    You my want to look at RedisJSON module where you can store arrays.

    Login or Signup to reply.
  2. You are using two different keys :

    • a hash named user1
    • a list named user2user1

    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 key user2user1 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search