6

I have a hash in Redis that has two subkeys and corresponding values as:

redis 127.0.0.1:6379> hgetall hash-key
1) "sub-key1"
2) "value1"
3) "sub-key2"
4) "value2"

How can I fetch only the subkeys from the hash i.e "sub-key1" , "sub-key2"?

TheTechRobo
1,39517 silver badges29 bronze badges
asked Feb 4, 2016 at 11:15

2 Answers 2

5

you need to use HKEYS command. see example below:

redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HKEYS myhash
1) "field1"
2) "field2"

Array reply: list of fields in the hash, or an empty list when key does not exist.

answered Feb 4, 2016 at 16:04
Sign up to request clarification or add additional context in comments.

Comments

2

You want HKEYS: http://redis.io/commands/hkeys

"HKEYS hash" returns an array of the fields within the hash.

answered Feb 4, 2016 at 11:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.