With the recent introduction of Redis modules (since Redis v4), redis is now a lot more flexible than the old redis. Previously in part 1, if you want to mimic the sorting and filtering behavior, you need to use set/sorted set and do the intersection/union by yourself. Not anymore. Meet RediSQL # RediSQL is an in-memory SQL engine, built on top of Redis as Redis module. It’s pretty much SQL under the hood now.
So Googling this question show a common approach using KEYS command and then pipe them to DEL command, which looks something like this in Lua script local keys = redis.call('keys', ARGV) for i=1,#keys,5000 do redis.call('del', unpack(keys, i, math.min(i+4999, #keys))) end return keys Doing things like this would be fine for development where the keyspace is small and frequent of use is low. However, if you were to do this at a larger keyspace and a lot more frequent, the KEYS command will block Redis instance and making other commands to fail.
tldr: RediSearch - a full text search redis module that is super fast. I learnt of RediSearch 2 years ago. It was a young project back then but seems very promising at time. When I revisit it last year, it’s quite mature already and was about to hit v1.0 so I did another test drive. The result was so good I put it on production few weeks later. Its pros are:
Set and sorted set are extremely powerful data types for filtering and sorting stuff with redis. Basic filtering # Let’s start with something simple. Usually filtering is just a matter of union and intersection. Let’s say: filter all hotels that are 3 or 4 star and have both spa and pool. For this, we just have to create a set for each of the filter criteria and do union/intersection accordingly.