supermario
supermario

Reputation: 2755

How to get number of elements in a redis hash map?

Assuming that myhash is like:

redis 127.0.0.1:6379> HSET myhash field1 "foo"
(integer) 1
redis 127.0.0.1:6379> HSET myhash field2 "bar"
(integer) 1
redis 127.0.0.1:6379> HGETALL myhash
1) "field1"
2) "Hello"
3) "field2"
4) "World"

How can I get number of myhash elements, that is 2, from redis-cli?

I'm learning redis from this tutorial but could not find my answer there.

Upvotes: 3

Views: 3386

Answers (1)

tddmonkey
tddmonkey

Reputation: 21184

You can use the HLEN command. Taken directly from the documentation at redis.io:

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

Upvotes: 4

Related Questions