2017-07-21 9 views
0

StackExchange.RedisからRedisでMSETを実行する方法はありますか?StackExchange.RedisのMSET

documentationを参照した後、私が書いた以下のコードは、StringSetAsyncを実行して、Redisで複数のキーと値のペアを追加することです。 IDatabase.StringSet(RedisKey[], RedisValue[])のようなものがありますか?

bool StringSet(KeyValuePair<RedisKey, RedisValue>[] values, When when = When.Always, CommandFlags flags = CommandFlags.None); 

だけ(これはあなたがMSET動作を取得することを意味しており、2番目と3番目のパラメータがデフォルト値であることを意味します)最初のパラメータを渡した:

public void Add(IEnumerable<CacheKeyValue> cacheKeyValues) 
    { 
     var tasks = new List<Task>(); 

     foreach(var kv in cacheKeyValues.ToList()) 
     { 
      tasks.Add(((Task<bool>)DB.StringSetAsync(kv.Key, ((RedisValue)kv.Value))).ContinueWith((b) => kv.Status = true)); 
     } 

     Task.WaitAll(tasks.ToArray()); 
    } 

答えて

1

あなたは呼びたいです。

https://github.com/StackExchange/StackExchange.Redis/blob/c4c9c1fdb455070415e82d2f104fc89a90b057b5/StackExchange.Redis/StackExchange/Redis/IDatabase.csあたりとして:

/// <summary> 
/// Sets the given keys to their respective values. If "not exists" is specified, this will not perform any operation at all even if just a single key already exists. 
/// </summary> 
/// <returns>True if the keys were set, else False</returns> 
/// <remarks>http://redis.io/commands/mset</remarks> 
/// <remarks>http://redis.io/commands/msetnx</remarks> 
Task<bool> StringSetAsync(KeyValuePair<RedisKey, RedisValue>[] values, When when = When.Always, CommandFlags flags = CommandFlags.None); 
+0

これはよさそうだ:async同等のもあります

/// <summary> /// Sets the given keys to their respective values. If "not exists" is specified, this will not perform any operation at all even if just a single key already exists. /// </summary> /// <returns>True if the keys were set, else False</returns> /// <remarks>http://redis.io/commands/mset</remarks> /// <remarks>http://redis.io/commands/msetnx</remarks> bool StringSet(KeyValuePair<RedisKey, RedisValue>[] values, When when = When.Always, CommandFlags flags = CommandFlags.None); 

。私はそれをテストし、答えとしてマークします。セットに複数のKey-Value/Pのペアを追加するのに似たようなものがありますか?私はredis(https://redis.io/commands#set)でも利用できないと思います。その場合、パイプライン化[https://stackexchange.github.io/StackExchange.Redis/PipelinesMultiplexers]を使用できます。 – Brij

+0

あなたはおそらく@Brijの完全に新しい質問を作成することをお勧めします。 – mjwills

関連する問題