0

I need to store some keys in the cache, that each one expires individually, but have them grouped. So I do something like this:

Connection.GetDatabase().StringSet($"Logged:{userID}", "", TimeSpan.FromSeconds(30));

At some point I want to get all the grouped keys, so following the example in library's github documentation https://github.com/StackExchange/StackExchange.Redis/blob/main/docs/KeysScan.md

I do this:

var servers = Connection.GetEndPoints();
return Connection.GetServer(servers[0]).Keys(pattern: "Logged:*);

But in the same page in github there is this warning

Either way, both SCAN and KEYS will need to sweep the entire keyspace, so should be avoided on production servers - or at least, targeted at replicas.

What else can I use to achieve what I want without using Keys, if we don't have replicas?

alfoks
  • 4,324
  • 4
  • 29
  • 44

0 Answers0