4

I have a scenario where I have to get all the keys (string type) matching some prefix. For example, I have below keys

 1. ABC.10
 2. ABC.11
 3. ABC.12 
 4. XYZ.10
 5. XYZ.11
 6. XYZ.12

And I need to get all keys matching XYZ using Stackexchange.Redis C#.

  • https://stackoverflow.com/questions/26488830/redis-stack-exchange-how-to-delete-or-get-keys-by-pattern might help – Vladimir Nov 23 '17 at 07:06
  • @Vladimir, I tried the code I the link but getting below error Timeout performing SCAN, inst: 1, mgr: ProcessReadQueue, err: never, queue: 2, qu: 0, qs: 2, qc: 0, wr: 0, wq: 0, in: 7, ar: 1, clientName: ComputerName, serverEndpoint: Unspecified/redisCacheServer.com:6379, IOCP: (Busy=0,Free=1000,Min=8,Max=1000), WORKER: (Busy=0,Free=32767,Min=8,Max=32767) (Please take a look at this article for some common client-side issues that can cause timeouts: http://stackexchange.github.io/StackExchange.Redis/Timeouts) – NeoDeveloper Nov 23 '17 at 07:59
  • Mark your answer as the accepted answer. I was looking for something similar. – Vincent P Dec 10 '18 at 12:14

1 Answers1

2

I found the way out to get the keys from Redis

 ConnectionMultiplexer con = RedisConnectionFactory.GetConnection();
 IServer server = con.GetServer("redisdb:6379");
  foreach (var key in server.Keys(DB_Number, "XYZ.*", 1000))
 {
   //logic
 }