Reputation: 2586
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"?
Upvotes: 6
Views: 6000
Reputation: 636
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.
Upvotes: 5
Reputation: 131
You want HKEYS: http://redis.io/commands/hkeys
"HKEYS hash" returns an array of the fields within the hash.
Upvotes: 2