redis stores keys and values in memory. Sometimes we want to find the numbers of keys in Redis

how to print the count number of keys

There are multiple ways to get keys count in redis First way,

127.0.0.1:6379> keys *
1) "roles"
127.0.0.1:6379> dbsize
(integer) 1
127.0.0.1:6379> info keyspace
# Keyspace
db0:keys=1,expires=0,avg_ttl=0
db2:keys=1,expires=0,avg_ttl=0

Command To get all avialiable keys

One way is using Key * command

Another way is using scan command redis-cli –scan –pattern ‘*'