Search code examples
redisnosqlkeydatabase-scan

Redis keys function for match with multiple pattern


How can I find keys with multiple match pattern, for example I have keys with

foo:*, event:*, poi:* and article:* patterns.

How can I find keys with redis keys function for match with foo:* or poi:* pattern, its like

find all keys with prefix foo:* or poi:*

Solution

  • You should not do this. KEYS is mainly a debug command. It is not supposed to be used for anything else.

    Redis is not a database supporting ad-hoc queries: you are supposed to provide access paths for the data you put into Redis (using extra set or hash or zset indexes).

    If you really need to run arbitrary boolean expressions on keys to select data, I would suggest to do it offline by using the rdb-redis-tools package.