Select subsections from hash in redis

I am completely new to Redis, so please excuse the question. I have a hash in redis that has two subkeys and corresponding values:

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

How can I extract only subkeys from the hash ie "turnkey1", "turnkey2"?

+4
source share
2 answers

you need to use the 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 response: a list of fields in the hash or an empty list if the key does not exist.

+2
source

Do you want HKEYS: http://redis.io/commands/hkeys

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

+1
source

Source: https://habr.com/ru/post/1627276/


All Articles