예제 #1
0
        public async Task Restore(Repositories.IBaseRepository <T> _templates)
        {
            var templates = await _templates.Get();

            foreach (var item in templates)
            {
                await _redisStore.Set(item.Id.ToCacheKey(""), item, null);
            }
        }
예제 #2
0
파일: RedisCache.cs 프로젝트: Gabina12/Ptms
 public async Task Appand(string key, T obj) {
     var cachedItems = await _cache.Get<List<T>>(key);
     if (cachedItems == null)
         cachedItems = new List<T>();
     else if (cachedItems.Any(x => x.Id == obj.Id)) {
         var item = cachedItems.First(x => x.Id == obj.Id);
         cachedItems.Remove(item);
     }
     cachedItems.Add(obj);
     await _cache.Remove(key);
     await _cache.Set(key, cachedItems, null);
 }
예제 #3
0
        public override bool Lock(string serviceKey, int expiryFromSeconds)
        {
            bool isLocked = false;

            try
            {
                string isAnyLocked = _redisStore.Get(serviceKey);

                if (String.IsNullOrEmpty(isAnyLocked))
                {
                    isLocked = _redisStore.Set(serviceKey, _token, expiryFromSeconds);

                    // When occurs any network problem within Redis, it could be provided consistent locking with secondary handler.
                    if (SecondaryLockHandler != null)
                    {
                        Task.Factory.StartNew(() => SecondaryLockHandler.Lock(serviceKey, expiryFromSeconds));
                    }
                }
            }
            catch
            {
                if (SecondaryLockHandler != null)
                {
                    isLocked = SecondaryLockHandler.Lock(serviceKey, expiryFromSeconds);
                }
            }

            return(isLocked);
        }