public async Task <bool> RemoveStringFromHashField(string hashSet, string key, string value) { var mutex = Semaphores.GetIndexSemaphore(hashSet, key); await mutex.WaitAsync(); try { var field = await GetHashField(hashSet, key); if (!string.IsNullOrEmpty(field)) { field = string.Join(",", field.Split(',').Where(x => x != value)); } if (string.IsNullOrEmpty(field)) { return(await _redisDatabase.HashDeleteAsync(hashSet.ToLower(), key.ToLower())); } return(await SetHashField(hashSet, key, Helpers.SerializeRedisValue(field))); } finally { mutex.Release(); } }
public async Task <bool> AppendStringToHashField(string hashSet, string key, string value) { var mutex = Semaphores.GetIndexSemaphore(hashSet, key); await mutex.WaitAsync(); try { var field = await GetHashField(hashSet, key); if (string.IsNullOrEmpty(field)) { field = value; } else if (field.Split(',').All(x => x != value)) { field += "," + value; } return(await SetHashField(hashSet, key, Helpers.SerializeRedisValue(field))); } finally { mutex.Release(); } }