BB.Caching.Cache.Shared.Hashes.SetIfNotExists C# (CSharp) Method

SetIfNotExists() public static method

Sets field in the hash stored at key to value, only if field does not yet exist. If key does not exist, a new key holding a hash is created. If field already exists, this operation has no effect.
http://redis.io/commands/hsetnx
public static SetIfNotExists ( RedisKey key, RedisValue field, RedisValue value ) : Task
key RedisKey
field RedisValue
value RedisValue
return Task
                public static Task<bool> SetIfNotExists(RedisKey key, RedisValue field, RedisValue value)
                {
                    var connections = SharedCache.Instance.GetWriteConnections(key);
                    Task<bool> result = null;
                    foreach (var connection in connections)
                    {
                        var task = connection
                            .GetDatabase(SharedCache.Instance.Db)
                            .HashSetAsync(key, field, value, When.NotExists);

                        if (null == result)
                            result = task;
                    }
                    return result;
                }
            }

Same methods

Cache.Shared.Hashes::SetIfNotExists ( RedisKey key, RedisValue field, RedisValue value ) : bool