I tried to retrieve keys with "prefix1|prefix2" But looking at the documentation it seems only 4-5 glob-style patterns are supported currently

Comment From: anoxic

The fact that this doesn't exist is a feature.

Comment From: itamarhaber

+1 @anoxic

Hello @Biboswan

Supporting full regex will increase the complexity of the command, whereas Redis attempts to keep things simple and transparent. If you really need that kind of functionality there are at least three ways you could go about it.

Way one: a Lua script.

Way two: a custom module - here's something along these lines although I'm not sure it is working anymore (or ever has)... maintaining things is hard ;)

Way three: use RedisGears likeso:

$ redis-cli SET foo1 bar1
OK
$ redis-cli SET baz2 qux2
OK
$ redis-cli SET key value
OK
$ redis-cli RG.PYEXECUTE "$(cat regexgear.py)"
1) 1) "TotalExecutionDuration"
   2) (integer) 48110
   3) "TotalReadDuration"
   4) (integer) 25118
2) 1) "baz2"
   2) "foo1"

regexgear.py:

import re

pat = re.compile('foo*|bar*')

GearsBuilder('KeysOnlyReader') \
    .filter(lambda x: pat.match(str(x))) \
    .run()

Comment From: stockholmux

@itamarhaber is right - you can do it those ways. However, just keep in mind that this is a bad idea™.

The keyspace in Redis is not practically indexed, meaning if you have billions of keys, any way you cut it will be a very expensive operation. Gears may not be blocking, but I'd re-evaluate the use of the keyspace if you need to do this operationally.

Comment From: Biboswan

thanks, @itamarhaber and @stockholmux. I just scanned twice with different patterns. Since Lua script is blocking it might be a good idea. RedisGears looks something interesting.