Beispiel #1
0
        public Result DoHttpWork(Request req)
        {
            var key = req.Query["key"];

            if (key == null)
            {
                return(Result.Fail("参数错误"));
            }

            try
            {
                RedisClientLocal = new CSRedisClient(SysConf.Main.RedisLocal.ConnectStrings);
                Logger.Main.Info($"[{Program.ModuleName}]初始化LOCAL REDIS CLIENT成功: \"{SysConf.Main.RedisLocal.ConnectStrings}\"");
            }
            catch (Exception ex)
            {
                Logger.Main.Error($"[{Program.ModuleName}]初始化LOCAL REDIS CLIENT失败: \"{SysConf.Main.RedisLocal.ConnectStrings}\", {ex.Message}");
            }

            if (req.Method == "GET")
            {
                if (!RedisClientLocal.Exists(key))
                {
                    return(Result.Fail($"Key: {key} 不存在"));
                }

                return(Result.Success(RedisClientLocal.Get(key)));
            }
            else if (req.Method == "POST")
            {
                string content = req.Body.AsString();
                return(Result.Success(RedisClientLocal.Set(key, content)));
            }
            return(Result.Fail($"不支持{req.Method}方法"));
        }
Beispiel #2
0
 public void Clear(string key)
 {
     if (!_client.Exists(key))
     {
         return;
     }
     _client.Del(key);
 }
Beispiel #3
0
 /// <summary>
 /// 是否存在此缓存
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool Exists(string key)
 {
     if (string.IsNullOrWhiteSpace(key))
     {
         throw new ArgumentNullException(nameof(key));
     }
     return(_cache.Exists(key));
 }
Beispiel #4
0
        /// <summary>
        /// exist value by key
        /// </summary>
        /// <param name="KeyName"></param>
        /// <returns></returns>
        public Boolean ExistKey(String KeyName)
        {
            if (conn == null)
            {
                throw new Exception("Connection has not initialize.");
            }

            return(conn.Exists(KeyName));
        }
Beispiel #5
0
        public async Task <TAgent> FetchById(string agentId)
        {
            var key = agentId;

            if (csredis.Exists(key))
            {
                return(JsonConvert.DeserializeObject <TAgent>(csredis.Get(key)));
            }
            else
            {
                return(null);
            }
        }
Beispiel #6
0
        private void SetKeyExpiration(CSRedisClient client, string cacheKey, Func <ICacheItemExpiration> expiration)
        {
            if (!client.Exists(cacheKey))
            {
                return;
            }

            var expiry = GetExpirationTime(expiration);

            if (expiry != null)
            {
                client.Expire(cacheKey, (int)expiry.Value.TotalSeconds);
            }
            else
            {
                client.Expire(cacheKey, TimeSpan.MaxValue);
            }
        }
        /// <summary>
        /// 判断锁定是否存在
        /// </summary>
        /// <param name="key"></param>
        /// <param name="limiter"></param>
        /// <returns></returns>
        public bool LockExists(IThrottleKey key, Limiter limiter)
        {
            string id = CreateLockKey(key, limiter);

            return(CSRedis.Exists(id));
        }
 /// <summary>
 /// 是否存在key
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool ContainsKey(string key)
 {
     return(_client.Exists(key));
 }
Beispiel #9
0
 public bool IsExist(string key)
 {
     return(_client.Exists(key));
 }
Beispiel #10
0
 /// <summary>
 /// 判断是否存在
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool Get(string key)
 {
     return(redisConnection.Exists(key));
 }
        public bool Exists(string id)
        {
            var key = GetKeyPrefix(id);

            return(_client.Exists(key));
        }
Beispiel #12
0
 /// <summary>
 /// 判斷Key是否存在
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool KeyExists(string key)
 {
     return(csredis.Exists(key));
 }
Beispiel #13
0
 public bool KeyExists(string key) => _instance.Exists(key);