Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StackExchange.Redis how to query all keys only on one db

I am newbie in redis, Now I want get all keys in one db without knowing about keys or pattern of keys. After googling,I found a sodu code about my issue, but i have no key pattern or data field in this code:

 var connection = ConnectionMultiplexer.Connect(new ConfigurationOptions
    {
        EndPoints = { { DemoSettings.CustomerRedisCache.Url, DemoSettings.CustomerRedisCache.Port } },
        Password = DemoSettings.CustomerRedisCache.Password
    });

    var server = connection.GetServer(host: DemoSettings.CustomerRedisCache.Url, 
                                      port: DemoSettings.CustomerRedisCache.Port);
    var cadena = "cust:" + data.SearchString.Replace(' ', ':')+"*";
    var valores = server.Keys(pattern: cadena);
like image 540
Arash Karami Avatar asked Jul 27 '15 16:07

Arash Karami


People also ask

How do I get Redis all keys?

Redis GET all Keys To list the keys in the Redis data store, use the KEYS command followed by a specific pattern. Redis will search the keys for all the keys matching the specified pattern. In our example, we can use an asterisk (*) to match all the keys in the data store to get all the keys.

What is lazy ConnectionMultiplexer?

It uses Lazy<T> to handle thread-safe initialization. It sets "abortConnect=false", which means if the initial connect attempt fails, the ConnectionMultiplexer will silently retry in the background rather than throw an exception.

What is a ConnectionMultiplexer?

The central object in StackExchange. Redis is the ConnectionMultiplexer class in the StackExchange. Redis namespace; this is the object that hides away the details of multiple servers. Because the ConnectionMultiplexer does a lot, it is designed to be shared and reused between callers.

What is Rediskey?

Redis Keys are Ideal for Keeping Track of Lots of Strings. For the (simple string) key-value data type Redis allows you to set, get, delete, and increment arbitrary string <key, value> pairs. You can only have 1 value at a time for each key (i.e. set is destructive assignment). You can also delete keys.


1 Answers

According to this link, the following code gets all the keys:

var keys = myCacheClient.SearchKeys("*");
like image 75
prashant patil Avatar answered Sep 20 '22 04:09

prashant patil