要撥打:
bool StringSet(KeyValuePair<RedisKey, RedisValue>[] values, When when = When.Always, CommandFlags flags = CommandFlags.None);
但只傳遞第一個參數(這將意味着第二個和第三個參數是默認值,這意味着你會得到MSET
行爲)。
按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>
bool StringSet(KeyValuePair<RedisKey, RedisValue>[] values, When when = When.Always, CommandFlags flags = CommandFlags.None);
還有一個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>
Task<bool> StringSetAsync(KeyValuePair<RedisKey, RedisValue>[] values, When when = When.Always, CommandFlags flags = CommandFlags.None);
這個不錯。我會測試它並將其標記爲答案。我們是否有類似的將多個鍵/值對添加到集合?我認爲它在redis中也不可用(https://redis.io/commands#set)。在這種情況下,我可以使用流水線[https://stackexchange.github.io/StackExchange.Redis/PipelinesMultiplexers]。 – Brij
您可能最好爲@Brij創建一個全新的問題。 – mjwills