看那MGET(http://redis.io/commands/mget)和MSET(http://redis.io/commands/mset)功能显示的Redis具有。这些在StackExchange.Redis客户端上受支持。
private static void MGet(CancellationToken cancellationToken)
{
var pairs = new KeyValuePair<RedisKey, RedisValue>[] {
new KeyValuePair<RedisKey,RedisValue>("key1", "value1"),
new KeyValuePair<RedisKey,RedisValue>("key2", "value2"),
new KeyValuePair<RedisKey,RedisValue>("key3", "value3"),
new KeyValuePair<RedisKey,RedisValue>("key4", "value4"),
new KeyValuePair<RedisKey,RedisValue>("key5", "value5"),
};
var keys = pairs.Select(p => p.Key).ToArray();
Connection.GetDatabase().StringSet(pairs);
var values = Connection.GetDatabase().StringGet(keys);
}
您将需要记住,在单个命令上获取或设置太多密钥可能会导致性能问题。