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
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
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