Stackexchange.redis: How to retrieve multiple values in list if we pass multiple Keys in a list ?

Created on 30 Sep 2014  ·  3Comments  ·  Source: StackExchange/StackExchange.Redis

I have a requirement of passing a List of keys and I need to get the list of values for that keys. Is it possible to retrieve bulk of key values?

cache.Set("A", Object1);
cache.Set("B", Object2);
List> redisbulkretrieve;
List sKeys = new List();
sKeys.Add("A");
sKeys.Add("B");

(List>)cache.get(sKeys) --> doesnot work..

can you help how to retrieve multiple values as list if we pass multiple Keys as list.

Most helpful comment

So:

var keys = new RedisKey[] { "A", "B" };
var values = cache.StringGet(keys);
var a = (string)values[0];
var b = (byte[])values[1];

or similar

All 3 comments

And what is "cache" in this example? The IDatabase API certainly has a multi-key API here:

RedisValue[] StringGet(RedisKey[] keys, CommandFlags flags = CommandFlags.None);

and a matching Async version; however, without knowledge of your "cache" type, I can't comment - because that doesn't look like SE.Redis' API

IDatabase cache = connection.GetDatabase();

I need to retrieve multiple list of Objects stored in Redis by sending a list of String keys.

So:

var keys = new RedisKey[] { "A", "B" };
var values = cache.StringGet(keys);
var a = (string)values[0];
var b = (byte[])values[1];

or similar

Was this page helpful?
0 / 5 - 0 ratings