コード例 #1
0
 public T Get <T>(string key, bool isDelay = false, int seconds = 30)
 {
     if (isDelay)
     {
         StackExchangeRedisHelper.Instance().SetExpire(key, seconds);
     }
     return(StackExchangeRedisHelper.Instance().Get <T>(key));
 }
コード例 #2
0
        /// <summary>
        /// 跳过式调用,如果事情正在被调用,直接跳过
        /// </summary>
        /// <param name="resource">锁定资源的标识</param>
        /// <param name="expiryTime">锁过期时间</param>
        /// <param name="work"></param>
        public static bool OverlappingWork(string resource, TimeSpan expiryTime, Action work)
        {
            var  redLock = StackExchangeRedisHelper.Instance().GetRedlock();
            Lock lockObject;
            bool locked;

            GetLockObjetc(resource, expiryTime, new TimeSpan(0), redLock, out lockObject, out locked);
            LockExec(work, redLock, lockObject, locked);
            return(locked);
        }
コード例 #3
0
        public bool Set(string key, string value, int seconds = 30)
        {
            bool flag = StackExchangeRedisHelper.Instance().Set(key, value);

            if (seconds > 0)
            {
                StackExchangeRedisHelper.Instance().SetExpire(key, seconds);
            }
            return(flag);
        }
コード例 #4
0
 public bool Delete(string key)
 {
     StackExchangeRedisHelper.Instance().Remove(key);
     return(true);
 }