How can I get the number of keys in redis?

I can get some keys with this command:

keys *_products_*

However, this command returns all the keys where I just need to count them. How can i get it?

+4
source share
4 answers

You can use DBSIZE or INFO KEYSPACE

But if you want all the keys with a specific pattern in the name you need to use KEYS or SCAN. And you need to pay attention to KEYS, starting it in the production process can affect performance, so you should use it with caution.

+5
source

() KEYS, SCAN counts, . Lua script, .

.

KEYS ( SCAN) - , . , , , . Redis Set, - SADD, , patter *products*, .

.

, .

+1

:

redis-cli --scan --pattern '*_products_*' | wc -l
0

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


All Articles