public async Task <ServiceRegistryEntity> Remove(ServiceRegistryEntity entity) { var serviceTag = entity.Tag; var serviceTagExists = await _db.KeyExistsAsync(serviceTag); if (!serviceTagExists) { return(null); } var serviceInstancesJson = await _db.StringGetAsync(serviceTag); var serviceInstances = JsonConvert.DeserializeObject <IList <ServiceRegistryEntity> >(serviceInstancesJson); serviceInstances.Remove(serviceInstances.First(x => x.Id == entity.Id)); if (serviceInstances.Count != 0) { await _db.StringSetAsync(serviceTag, JsonConvert.SerializeObject(serviceInstances)); } else { var servicesTagsJson = await _db.StringGetAsync(_servicesTagsKey); var servicesTags = JsonConvert.DeserializeObject <IList <string> >(servicesTagsJson); servicesTags.Remove(serviceTag); await _db.StringSetAsync(_servicesTagsKey, JsonConvert.SerializeObject(servicesTags)); await _db.KeyDeleteAsync(serviceTag); } return(entity); }
public async Task <bool> DeleteAsync(IDatabaseAsync redisDatabase, TKey key) { var headerKey = _keygen.GetKey(key); var chunkDeletes = new List <Task <bool> >(); using (var redisLock = _lockFactory.GetLockInstance(headerKey)) { await redisLock.AcquireAsync().ConfigureAwait(false); var header = await redisDatabase.StringGetAsync(headerKey).ConfigureAwait(false); if (header.IsNullOrEmpty) { return(false); } var chunkCount = (int)header; for (var chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++) { var chunkKey = _keygen.GetKey(key, chunkIndex.ToString()); chunkDeletes.Add(redisDatabase.KeyDeleteAsync(chunkKey)); } await Task.WhenAll(chunkDeletes).ConfigureAwait(false); return(await redisDatabase.KeyDeleteAsync(headerKey).ConfigureAwait(false)); } }
private async Task <bool> RemoveToken(GrantedToken grantedToken) { var idTask = _database.KeyDeleteAsync(grantedToken.Id); var scopeTokenTask = _database.KeyDeleteAsync(grantedToken.ClientId + grantedToken.Scope); var accessTokenTask = _database.KeyDeleteAsync(grantedToken.AccessToken); var refreshTokenTask = grantedToken.RefreshToken == null ? Task.FromResult(true) : _database.KeyDeleteAsync(grantedToken.RefreshToken); return((await Task.WhenAll(idTask, scopeTokenTask, accessTokenTask, refreshTokenTask).ConfigureAwait(false)) .All(x => x)); }
public async Task <bool> IsCrossNodeApiInvolvedAsync(long requestId) { var value = await _redisDb.SetMembersAsync(requestId.ToString()).ConfigureAwait(false); await _redisDb.KeyDeleteAsync(requestId.ToString(), CommandFlags.FireAndForget).ConfigureAwait(false); return(!value?.FirstOrDefault().IsNullOrEmpty ?? false); }
public void Remove( IDatabaseAsync context, IEnumerable <TValue> items) { foreach (var item in items) { var masterKey = GenerateKeyName(_masterKeyExtractor(item)); context.KeyDeleteAsync(masterKey); } }
public async Task <bool> RemoveFromCache(string key) { var result = await db.KeyDeleteAsync(key); if (!result) { return(await Task.FromResult(false)); } return(await Task.FromResult(true)); }
private static async Task SyncRedisKeyAsync(IDatabaseAsync srcDatabase, RedisKey redisKey, IDatabaseAsync destDatabase) { if (await destDatabase.KeyExistsAsync(redisKey)) { await destDatabase.KeyDeleteAsync(redisKey); } var type = await srcDatabase.KeyTypeAsync(redisKey); switch (type) { case RedisType.String: var strVal = await srcDatabase.StringGetAsync(redisKey); await destDatabase.StringSetAsync(redisKey, strVal); break; case RedisType.List: var list = await srcDatabase.ListRangeAsync(redisKey); await destDatabase.ListRightPushAsync(redisKey, list); break; case RedisType.Set: var set = await srcDatabase.SetMembersAsync(redisKey); await destDatabase.SetAddAsync(redisKey, set); break; case RedisType.SortedSet: var zset = await srcDatabase.SortedSetRangeByRankWithScoresAsync(redisKey); await destDatabase.SortedSetAddAsync(redisKey, zset); break; case RedisType.Hash: var hash = await srcDatabase.HashGetAllAsync(redisKey); await destDatabase.HashSetAsync(redisKey, hash); break; default: throw new ArgumentOutOfRangeException(); } }
public async Task <CacheItem <TItem> > RemoveAsync <TItem>(string key) where TItem : class { // Using fail-first patterns, check valid params supplied prior to any futher processing if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException(nameof(key)); } var memItem = await this.GetAsync <TItem>(key); await _redisStore.KeyDeleteAsync(key); return(memItem); }
public async ValueTask <bool> RemoveAsync(ServiceContext context) { if (await inmemoryGroup.RemoveAsync(context)) // if inmemoryGroup.Remove succeed, removed from.RedisGroupRepository. { await database.KeyDeleteAsync(counterKey).ConfigureAwait(false); await mq.UnsubscribeAsync(); return(true); } else { await database.StringIncrementAsync(counterKey, -1).ConfigureAwait(false); } return(false); }
public void Dispose() { GC.SuppressFinalize(this); string END_POINT_KEY = "REDIS_EVENT_SOURCE_PRODUCER_ENDPOINT"; string PASSWORD_KEY = "REDIS_EVENT_SOURCE_PRODUCER_PASS"; string key = $"{PARTITION}:{SHARD}"; var redisClientFactory = new RedisClientFactory( _fakeLogger, $"Test {DateTime.Now: yyyy-MM-dd HH_mm_ss}", RedisUsageIntent.Admin, null, END_POINT_KEY, PASSWORD_KEY); IDatabaseAsync db = redisClientFactory.GetDbAsync().Result; db.KeyDeleteAsync(key, CommandFlags.DemandMaster).Wait(); }
public async Task DeleteAll(IDatabaseAsync database, IDataKey key) { if (database == null) { throw new ArgumentNullException(nameof(database)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } logger.LogDebug("DeleteAll: [{0}]", key); var deleteKeys = mainIndexManager.Delete(database, key); var keys = await GetAllKeys(database, key).ConfigureAwait(false); await database.KeyDeleteAsync(keys.ToArray()).ConfigureAwait(false); await Task.WhenAll(deleteKeys).ConfigureAwait(false); }
public static Task DeleteAll(this IRedisLink link, IDatabaseAsync database, IDataKey key) { if (link == null) { throw new ArgumentNullException(nameof(link)); } if (database == null) { throw new ArgumentNullException(nameof(database)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } var actualKey = link.GetKey(key); return(database.KeyDeleteAsync(actualKey)); }
public async ValueTask ReleaseAsync(CancellationToken cancellationToken) { if (_lockValue == null) { throw new InvalidOperationException("Lock has not been acquired yet."); } var value = await _database.StringGetAsync(GetRedisKey()) .ConfigureAwait(false); if (!value.HasValue) { return; // Value has expired or was released by another thread. } if (value != _lockValue) { throw new InvalidOperationException("Cannot release lock as another thread has acquired it."); } await _database.KeyDeleteAsync(GetRedisKey()) .ConfigureAwait(false); }
public async ValueTask <bool> KeyDeleteAsync(string key) { return(await _database.KeyDeleteAsync(key)); }
/// <summary> /// 删除一个对象 /// </summary> /// <param name="cache"></param> /// <param name="key"></param> /// <returns></returns> public static async Task <bool> DelAsync(this IDatabaseAsync cache, string key) { return(await cache.KeyDeleteAsync(key).ConfigureAwait(false)); }
private Task <bool> Clear(IDatabaseAsync database, Feature feature) { return(database.KeyDeleteAsync(feature.Key)); }
/// <inheritdoc /> public Task <bool> Remove(string ticketId, CancellationToken cancellationToken) { return(_database.KeyDeleteAsync(ticketId)); }
public Task <bool> Delete(Consent record, CancellationToken cancellationToken) { return(_database.KeyDeleteAsync(record.Subject)); }
public Task DeleteAsync <TKey>(TKey key) where TKey : ICacheKey { return(_database.KeyDeleteAsync(key.ExtractKey())); }
/// <inheritdoc/> public async Task Remove(IDatabaseAsync db) { await db.KeyDeleteAsync(this.Key); }
public async Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState) { var key = GetKey(grainType, grainReference, grainState); await _db.KeyDeleteAsync(key); }
/// <inheritdoc /> public Task <bool> Remove(string code, CancellationToken cancellationToken) { return(_database.KeyDeleteAsync(code)); }
public async Task <bool> Remove(string key) { return(await redisDb.KeyDeleteAsync(key, CommandFlags.HighPriority).ConfigureAwait(false)); }
public async Task RemoveKey(string key) { IDatabaseAsync db = connection.GetDatabase(DB_INDEX); await db.KeyDeleteAsync(key); }
public async Task <bool> Remove(TKey id) { return(await _db.KeyDeleteAsync(string.Format(_keyFormat, id))); }
public async Task <bool> Remove(string key) { return(await redisDb.KeyDeleteAsync(key).ConfigureAwait(false)); }
public Task <bool> DeleteAsync(IDatabaseAsync redisDatabase, TKey key) { return(redisDatabase.KeyDeleteAsync(_keygen.GetKey(key))); }
public Task Reset(IDatabaseAsync database, IIndexKey indexes) { log.LogDebug("Reset"); return(database.KeyDeleteAsync(Link.GetIndexKey(indexes))); }
private static TupleList <string, Task> RunStackExchangeAsync(string prefix, IDatabaseAsync db) { var tasks = new TupleList <string, Func <Task> >() { { "DebugObjectAsync", () => db.DebugObjectAsync($"{prefix}DebugObjectAsync") }, { "ExecuteAsync", () => db.ExecuteAsync("DDCUSTOM", "COMMAND") }, { "GeoAddAsync", () => db.GeoAddAsync($"{prefix}GeoAddAsync", new GeoEntry(1.5, 2.5, "member")) }, { "GeoDistanceAsync", () => db.GeoDistanceAsync($"{prefix}GeoDistanceAsync", "member1", "member2") }, { "GeoHashAsync", () => db.GeoHashAsync($"{prefix}GeoHashAsync", "member") }, { "GeoPositionAsync", () => db.GeoPositionAsync($"{prefix}GeoPositionAsync", "member") }, { "GeoRadiusAsync", () => db.GeoRadiusAsync($"{prefix}GeoRadiusAsync", "member", 2.3) }, { "GeoRemoveAsync", () => db.GeoRemoveAsync($"{prefix}GeoRemoveAsync", "member") }, { "HashDecrementAsync", () => db.HashDecrementAsync($"{prefix}HashDecrementAsync", "hashfield", 4.5) }, { "HashDeleteAsync", () => db.HashDeleteAsync($"{prefix}HashDeleteAsync", "hashfield") }, { "HashExistsAsync", () => db.HashExistsAsync($"{prefix}HashExistsAsync", "hashfield") }, { "HashGetAllAsync", () => db.HashGetAllAsync($"{prefix}HashGetAllAsync") }, { "HashIncrementAsync", () => db.HashIncrementAsync($"{prefix}HashIncrementAsync", "hashfield", 1.5) }, { "HashKeysAsync", () => db.HashKeysAsync($"{prefix}HashKeysAsync") }, { "HashLengthAsync", () => db.HashLengthAsync($"{prefix}HashLengthAsync") }, { "HashSetAsync", () => db.HashSetAsync($"{prefix}HashSetAsync", new HashEntry[] { new HashEntry("x", "y") }) }, { "HashValuesAsync", () => db.HashValuesAsync($"{prefix}HashValuesAsync") }, { "HyperLogLogAddAsync", () => db.HyperLogLogAddAsync($"{prefix}HyperLogLogAddAsync", "value") }, { "HyperLogLogLengthAsync", () => db.HyperLogLogLengthAsync($"{prefix}HyperLogLogLengthAsync") }, { "HyperLogLogMergeAsync", () => db.HyperLogLogMergeAsync($"{prefix}HyperLogLogMergeAsync", new RedisKey[] { "key1", "key2" }) }, { "IdentifyEndpointAsync", () => db.IdentifyEndpointAsync() }, { "KeyDeleteAsync", () => db.KeyDeleteAsync("key") }, { "KeyDumpAsync", () => db.KeyDumpAsync("key") }, { "KeyExistsAsync", () => db.KeyExistsAsync("key") }, { "KeyExpireAsync", () => db.KeyExpireAsync("key", DateTime.Now) }, // () => db.KeyMigrateAsync("key", ???) { "KeyMoveAsync", () => db.KeyMoveAsync("key", 1) }, { "KeyPersistAsync", () => db.KeyPersistAsync("key") }, { "KeyRandomAsync", () => db.KeyRandomAsync() }, { "KeyRenameAsync", () => db.KeyRenameAsync("key1", "key2") }, { "KeyRestoreAsync", () => db.KeyRestoreAsync("key", new byte[] { 0, 1, 2, 3, 4 }) }, { "KeyTimeToLiveAsync", () => db.KeyTimeToLiveAsync("key") }, { "KeyTypeAsync", () => db.KeyTypeAsync("key") }, { "ListGetByIndexAsync", () => db.ListGetByIndexAsync("listkey", 0) }, { "ListInsertAfterAsync", () => db.ListInsertAfterAsync("listkey", "value1", "value2") }, { "ListInsertBeforeAsync", () => db.ListInsertBeforeAsync("listkey", "value1", "value2") }, { "ListLeftPopAsync", () => db.ListLeftPopAsync("listkey") }, { "ListLeftPushAsync", () => db.ListLeftPushAsync("listkey", new RedisValue[] { "value3", "value4" }) }, { "ListLengthAsync", () => db.ListLengthAsync("listkey") }, { "ListRangeAsync", () => db.ListRangeAsync("listkey") }, { "ListRemoveAsync", () => db.ListRemoveAsync("listkey", "value3") }, { "ListRightPopAsync", () => db.ListRightPopAsync("listkey") }, { "ListRightPopLeftPushAsync", () => db.ListRightPopLeftPushAsync("listkey", "listkey2") }, { "ListRightPushAsync", () => db.ListRightPushAsync("listkey", new RedisValue[] { "value5", "value6" }) }, { "ListSetByIndexAsync", () => db.ListSetByIndexAsync("listkey", 0, "value7") }, { "ListTrimAsync", () => db.ListTrimAsync("listkey", 0, 1) }, { "LockExtendAsync", () => db.LockExtendAsync("listkey", "value7", new TimeSpan(0, 0, 10)) }, { "LockQueryAsync", () => db.LockQueryAsync("listkey") }, { "LockReleaseAsync", () => db.LockReleaseAsync("listkey", "value7") }, { "LockTakeAsync", () => db.LockTakeAsync("listkey", "value8", new TimeSpan(0, 0, 10)) }, { "PublishAsync", () => db.PublishAsync(new RedisChannel("channel", RedisChannel.PatternMode.Auto), "somemessage") }, // { "ScriptEvaluateAsync", () => db.ScriptEvaluateAsync(} { "SetAddAsync", () => db.SetAddAsync("setkey", "value1") }, { "SetCombineAndStoreAsync", () => db.SetCombineAndStoreAsync(SetOperation.Union, "setkey", new RedisKey[] { "value2" }) }, { "SetCombineAsync", () => db.SetCombineAsync(SetOperation.Union, new RedisKey[] { "setkey1", "setkey2" }) }, { "SetContainsAsync", () => db.SetContainsAsync("setkey", "value1") }, { "SetLengthAsync", () => db.SetLengthAsync("setkey") }, { "SetMembersAsync", () => db.SetMembersAsync("setkey") }, { "SetMoveAsync", () => db.SetMoveAsync("setkey1", "setkey2", "value2") }, { "SetPopAsync", () => db.SetPopAsync("setkey1") }, { "SetRandomMemberAsync", () => db.SetRandomMemberAsync("setkey") }, { "SetRandomMembersAsync", () => db.SetRandomMembersAsync("setkey", 2) }, { "SetRemoveAsync", () => db.SetRemoveAsync("setkey", "value2") }, { "SortAndStoreAsync", () => db.SortAndStoreAsync("setkey2", "setkey") }, { "SortAsync", () => db.SortAsync("setkey") }, { "SortedSetAddAsync", () => db.SortedSetAddAsync("ssetkey", new SortedSetEntry[] { new SortedSetEntry("value1", 1.5), new SortedSetEntry("value2", 2.5) }) }, { "SortedSetCombineAndStoreAsync", () => db.SortedSetCombineAndStoreAsync(SetOperation.Union, "ssetkey1", "ssetkey2", "ssetkey3") }, { "SortedSetDecrementAsync", () => db.SortedSetDecrementAsync("ssetkey", "value1", 1) }, { "SortedSetIncrementAsync", () => db.SortedSetIncrementAsync("ssetkey", "value2", 1) }, { "SortedSetLengthAsync", () => db.SortedSetLengthAsync("ssetkey") }, { "SortedSetLengthByValueAsync", () => db.SortedSetLengthByValueAsync("ssetkey", "value1", "value2") }, { "SortedSetRangeByRankAsync", () => db.SortedSetRangeByRankAsync("ssetkey") }, { "SortedSetRangeByRankWithScoresAsync", () => db.SortedSetRangeByRankWithScoresAsync("ssetkey") }, { "SortedSetRangeByScoreAsync", () => db.SortedSetRangeByScoreAsync("ssetkey") }, { "SortedSetRangeByScoreWithScoresAsync", () => db.SortedSetRangeByScoreWithScoresAsync("ssetkey") }, { "SortedSetRangeByValueAsync", () => db.SortedSetRangeByValueAsync("ssetkey") }, { "SortedSetRankAsync", () => db.SortedSetRankAsync("ssetkey", "value1") }, { "SortedSetRemoveAsync", () => db.SortedSetRemoveAsync("ssetkey", "value1") }, { "SortedSetRemoveRangeByRankAsync", () => db.SortedSetRemoveRangeByRankAsync("ssetkey", 0, 1) }, { "SortedSetRemoveRangeByScoreAsync", () => db.SortedSetRemoveRangeByScoreAsync("ssetkey", 0, 1) }, { "SortedSetRemoveRangeByValueAsync", () => db.SortedSetRemoveRangeByValueAsync("ssetkey", "value1", "value2") }, { "SortedSetScoreAsync", () => db.SortedSetScoreAsync("ssestkey", "value1") }, { "StringAppendAsync", () => db.StringAppendAsync("ssetkey", "value1") }, { "StringBitCountAsync", () => db.StringBitCountAsync("ssetkey") }, { "StringBitOperationAsync", () => db.StringBitOperationAsync(Bitwise.And, "ssetkey1", new RedisKey[] { "ssetkey2", "ssetkey3" }) }, { "StringBitPositionAsync", () => db.StringBitPositionAsync("ssetkey1", true) }, { "StringDecrementAsync", () => db.StringDecrementAsync("key", 1.45) }, { "StringGetAsync", () => db.StringGetAsync("key") }, { "StringGetBitAsync", () => db.StringGetBitAsync("key", 3) }, { "StringGetRangeAsync", () => db.StringGetRangeAsync("key", 0, 1) }, { "StringGetSetAsync", () => db.StringGetSetAsync("key", "value") }, { "StringGetWithExpiryAsync", () => db.StringGetWithExpiryAsync("key") }, { "StringIncrementAsync", () => db.StringIncrementAsync("key", 1) }, { "StringLengthAsync", () => db.StringLengthAsync("key") }, { "StringSetAsync", () => db.StringSetAsync(new KeyValuePair <RedisKey, RedisValue>[] { new KeyValuePair <RedisKey, RedisValue>("key", "value") }) }, { "StringSetBitAsync", () => db.StringSetBitAsync("key", 0, true) }, { "StringSetRangeAsync", () => db.StringSetRangeAsync("key", 3, "value") }, }; var pending = new TupleList <string, Task>(); foreach (var item in tasks) { try { pending.Add(item.Item1, item.Item2()); } catch (Exception e) { while (e.InnerException != null) { e = e.InnerException; } Console.WriteLine($"{e.Message}"); } } return(pending); }
public Task InvalidateValueAsync(string key) { return(_redis.KeyDeleteAsync(key)); }
private Task<bool> Clear(IDatabaseAsync database, Feature feature) { return database.KeyDeleteAsync(feature.Key); }