Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redis how to limit the return number of KEYS command?

Tags:

redis

I get values with "KEYS p_*" command in redis.

But with "KEYS p_*" , if the redis has millions of keys,I will get too many values and bad performence.

So can I just get 100 values with "KEYS p_*" command?

like image 718
杜智超 Avatar asked Jun 03 '15 05:06

杜智超


People also ask

Which command is used to return the number of elements in a set in Redis?

The SCARD command returns the cardinality (i.e. number of items) of a Redis set.

How can I get total number of keys in Redis?

The first command you can use to get the total number of keys in a Redis database is the DBSIZE command. This simple command should return the total number of keys in a selected database as an integer value. The above example command shows that there are 203 keys in the database at index 10.

How many keys we can store in Redis?

Redis can handle up to 2^32 keys, and was tested in practice to handle at least 250 million keys per instance. Every hash, list, set, and sorted set, can hold 2^32 elements. In other words your limit is likely the available memory in your system.


1 Answers

SCAN is recommended for production, so you can use something like:

SCAN 0 COUNT 100 MATCH p_* 

and keep getting the next page
for more details see the SCAN command:
http://redis.io/commands/scan

like image 160
Liviu Costea Avatar answered Oct 02 '22 15:10

Liviu Costea