Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all keys (string type) with prefix from Redis in Stackexchange.Redis

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#.

like image 387
NeoDeveloper Avatar asked Oct 20 '25 10:10

NeoDeveloper


1 Answers

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
 }
like image 75
NeoDeveloper Avatar answered Oct 22 '25 01:10

NeoDeveloper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!