I have a Redis cache, I have set a few keys in that, and now I need to get all the keys and their values. It seems that there is no direct method to get this.
I can see only StringGet(string key)
method which takes a key as a parameter. But no method there for all the keys
Edit:
I have tied the below code, but it’s giving an exception on 3rd line.
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
var keys = redis.GetServer("localhost").Keys();
string[] keysArr = keys.Select(key => (string)key).ToArray();
foreach (string key in keysArr)
{
Console.Write(db.StringGet(key));
}
Exception:
the specified endpoint is not defined
2
Answers
You can call the
Keys
method to get all the keys, remember you need to passallowAdmin=true"
in theConnect
method.You can try this way