Is it possible to get all the keys that start with a digit(e.g. 12.2323.MKSUID
)? the KEYS
command is supposed to support patterns but what kind of patterns/regex flavour ? I've tried KEYS \d
with no result.
Asked
Active
Viewed 2,495 times
1

user7425610
- 55
- 3
-
[The documentation](https://redis.io/commands/keys) explains it clearly. – ndnenkov Feb 21 '17 at 16:08
-
Please read the documentation regarding `KEYS` carefully: > **Warning:** consider KEYS as a command that should only be used in production environments with extreme care. – Itamar Haber Feb 21 '17 at 16:42
-
Please avoid using KEYS and opt for SCAN instead – Not_a_Golfer Feb 21 '17 at 20:39
3 Answers
4
The KEYS command supports glob style patterns. To match keys that start with a digit, you can use the pattern:
KEYS [0-9]*
As Itamar notes, be careful using KEYS with a pattern match against a live system, it can severely impact performance.
More details and examples can be found in the description of KEYS on redis.io

Itamar Haber
- 47,336
- 7
- 91
- 117

Tague Griffith
- 3,963
- 2
- 20
- 24
4
This question has some good info. Like the comment suggested, better to use scan:
SCAN 0 MATCH "[0-9]*"

Community
- 1
- 1

systemjack
- 2,815
- 17
- 26
1
For getting keys that starts with digit.
KEYS [0-9]*

Sahil Gulati
- 15,028
- 4
- 24
- 42
-
1For the sake of future readers: while this answer is 100% correct - KEYS should be avoided in real world situations, and you should use SCAN instead. – Not_a_Golfer Feb 21 '17 at 20:40