Finding keys using wildcards

No, there is no command to do that. But it would be trivial to implement it on client side, if you really have to.

Applications should never use the KEYS commands to retrieve data. KEYS blocks the whole Redis instance while it is scanning linearly the millions of keys you have stored. It is more a debugging command supposed to be used in administration tools.

With Redis, there is no btree structure to index the keys, so you cannot query for keys, except if your keys are stored in an existing collection (set, zset, etc ...)


You can use the SCAN command in redis to search for keys without blocking the whole database.

redis SCAN docs

This command has an optional MATCH filter that works much like the filter on the KEYS command.

redis> SCAN 0 MATCH party:*

1) <the cursor>
2) 1) "party:congress:president"
   2) "party:bjp:president"
   3) "party:bjp"
   4) "party:sena"

keep calling until the cursor returns back to 0 to get all parties (might not get ALL parties if they are being inserted while you are scanning)

available since 2.8


I think if you want to get the 'parties' data from redis then each time you save your regular data you also save the party name to the parties list, then you can get it easily


You can use KEYS and * wildcard.

Example

SET user:1 Amir
SET user:2 Jack

To get all users using wildcard:

KEYS user:*

The result will be:

1) "user:1"
2) "user:2"

Tags:

Redis