Currently I have created a NestJS application with a Redis Cache. I want to be able to get multiple keys from my Redis Cache by using a pattern where I can get all the keys that include some string.
Currently I am using cache-manager and cache-manager-redis-store as my client to be able to connect and access my Redis Cache. I have gone through the documentation to try and use the .mget() function but I am not able to figure out if I can somehow pass a string and get all the keys that include that string.
Im thinking I might have to go with a different Redis client but just wanted to see if anyone had any other ideas.
2
Answers
There are two ways you can accomplish this
keep a SET of keys that you want to retrieve and do SMEMBERS. However, you will have to manually maintain the SET and add and remove.
Redisearch allows you to create secondary indices around data for full text search etc
There is property named
store
incache-manager
from which you can get all keys by callingkeys()
method.This is example redisService
Then you can use this service to get multiple keys or can get values of multiple keys
await this.redisService.getKeys('*' + email + '*');
Also you can get values of multiple keys
await this.redisService.getMultipleKeydata('*' + email + '*');