Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get all of the sets in redis?

Tags:

redis

I know the KEYS command, but that only returns the keys (I'm guessing all of the keys with type String), and apparently sets aren't considered keys.

Is there a command for getting all of the sets in the database? What about other data types (hash, list, sorted set)?

http://redis.io/topics/data-types

like image 875
beatgammit Avatar asked Sep 18 '11 15:09

beatgammit


People also ask

How do I get everything from Redis?

Redis GET all Keys To list the keys in the Redis data store, use the KEYS command followed by a specific pattern. Redis will search the keys for all the keys matching the specified pattern. In our example, we can use an asterisk (*) to match all the keys in the data store to get all the keys.

How do I view the contents of Redis cache?

By clicking on a Redis key name, all its contents will open in a new editor tab. With a collection type Redis key, clicking on it will reveal the individual elements under the key name. Clicking the individual element will display its contents in a new editor tab.

How do I view Redis data?

A Redis server has 16 databases by default. You can check the actual number by running redis-cli config get databases. In interactive mode, the database number is displayed in the prompt within square braces. For example, 127.0. 0.1:6379[13] shows that the 13th database is in use.

What is set and get in Redis?

The Redis “get set” (GETSET) command allows you to set a key to a specified value and return the old value that was stored at the key. The Redis GETSET command is often used in conjunction with the INCR command to handle counting.


2 Answers

I know the KEYS command, but that only returns the keys (I'm guessing all of the keys with type String), and apparently sets aren't considered keys.

KEYS command return results no matter what data type are your keys, since it searches key names. At the lowest level of abstraction each data type in redis is key/value based where value can be represented as one of several (advanced) data structures (string, hash, list, set, sorted set). You can see that KEYS command also work for sets in it's examples.

Is there a command for getting all of the sets in the database? What about other data types (hash, list, sorted set)?

As far as I know there is no dedicated command for this functionality and KEYS command is applied on entire data set of your database. However there is a TYPE command which can determine data type of specified key.

like image 87
yojimbo87 Avatar answered Sep 24 '22 07:09

yojimbo87


The answer was correct for its time, however this is supported from redis 2.8.0 - Check out SCAN

like image 24
Amnon Avatar answered Sep 22 '22 07:09

Amnon