Beispiel #1
0
 public void Clear(string key)
 {
     if (!_client.Exists(key))
     {
         return;
     }
     _client.Del(key);
 }
        public void 缓存壳()
        {
            //不加缓存的时候,要从数据库查询
            string str1 = "val";

            //1一般的缓存代码,如不封装还挺繁琐的
            var cacheValue = rds.Get("test1");

            if (!string.IsNullOrEmpty(cacheValue))
            {
                try
                {
                    var obj = JsonConvert.DeserializeObject(cacheValue);
                }
                catch
                {
                    //出错时删除key
                    rds.Del("test1");
                    throw;
                }
            }
            rds.Set("test1", JsonConvert.SerializeObject(str1), 10); //缓存10秒

            //2使用缓存壳效果同上,以下示例使用 string 和 hash 缓存数据
            var t1 = rds.CacheShell("test1", 10, () => str1);
            var t2 = rds.CacheShell("test", "1", 10, () => str1);
            var t3 = rds.CacheShell("test", new[] { "1", "2" }, 10, notCacheFields => new[] { ("1", str1), ("2", str1) });
Beispiel #3
0
 public static void M5_SetNxRemove(this CSRedisClient client, string key, string selfMark)
 {
     //判断是否是自己的锁
     if (client.Get(key) == selfMark)
     {
         client.Del(key);
     }
 }
Beispiel #4
0
        public async Task <int> PurgeAllAgents()
        {
            var keys = csredis.Keys($"{prefix}*");

            csredis.Del(keys.Select(x => x.Substring(prefix.Length)).ToArray());

            return(keys.Count());
        }
Beispiel #5
0
                /// <summary>
                /// 设置缓存
                /// </summary>
                /// <param name="key"></param>
                /// <param name="value"></param>
                public void SetCache(string key, object value)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            var v = _cache.Get <object>(key);

            if (v != null)
            {
                _cache.Del(key);
            }
            _cache.Set(key, value);
        }
Beispiel #6
0
        /// <summary>
        /// delete value by key
        /// </summary>
        /// <param name="KeyName"></param>
        /// <returns></returns>
        public Int32 DeleteValue(String[] KeyName)
        {
            if (conn == null)
            {
                throw new Exception("Connection has not initialize.");
            }

            return((int)conn.Del(KeyName));
        }
Beispiel #7
0
        public void Remove(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            _redisClient.Del(key.Split('|'));
            // TODO: Error handling
        }
Beispiel #8
0
 /// <summary>
 /// 用于在 key 存在时删除 key
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static long Delete(params string[] key)
 {
     try
     {
         return(_redisManager.Del(key));
     }
     catch (Exception)
     {
         return(0);
     }
 }
        public DataProtectionRedisTests(ITestOutputHelper output)
        {
            _output = output;

            _config = new ConfigurationBuilder()
                      .SetBasePath(AppContext.BaseDirectory)
                      .AddJsonFile("testconfig.json")
                      .Build();


            _redisClient = new CSRedisClient(_config["Test:Redis:Server"]);
            _redisClient.Del("Key");
        }
        public static void Test1(bool flush = true)
        {
            var client = new CSRedisClient("127.0.0.1:6379,password=,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=");

            if (flush)
            {
                client.Del("Test1");
            }

            client.SAdd("Test1", Guid.NewGuid());

            client.SAdd("Test1", Guid.NewGuid());

            client.SAdd("Test1", Guid.NewGuid());

            client.SAdd("Test1", Guid.Empty);

            client.SAdd("Test1", Guid.Empty);

            client.SRem("Test1", Guid.Empty);

            client.Dispose();
        }
        public void XmlRoundTripsToActualRedisServer()
        {
            var guid = Guid.NewGuid().ToString();
            var key  = "Test:DP:Key" + guid;

            try
            {
                var repo    = new CSRedisXmlRepository(_redisClient, key);
                var element = new XElement("HelloRedis", guid);
                repo.StoreElement(element, guid);

                Thread.Sleep(1000);

                var repo2    = new CSRedisXmlRepository(_redisClient, key);
                var elements = repo2.GetAllElements();

                Assert.Contains(elements, e => e.Name == "HelloRedis" && e.Value == guid);
            }
            finally
            {
                // cleanup
                _redisClient.Del(key);
            }
        }
Beispiel #12
0
 public static long DelKey(string key)
 {
     return(mRedisInstance.Del(key));
 }
Beispiel #13
0
 public void Remove(string key) => _instance.Del(key);
        /// <summary>
        /// 移除限制状态
        /// </summary>
        /// <param name="key"></param>
        /// <param name="limiter"></param>
        public void RemoveThrottle(IThrottleKey key, Limiter limiter)
        {
            string id = CreateThrottleKey(key, limiter);

            CSRedis.Del(id);
        }
 /// <summary>
 /// 删除key
 /// </summary>
 /// <param name="key"></param>
 public void Remove(string key)
 {
     _client.Del(key);
 }
Beispiel #16
0
 /// <summary>
 /// 移除
 /// </summary>
 /// <param name="key"></param>
 public void Remove(string key)
 {
     redisConnection.Del(key);
 }
 public void Clear()
 {
     redisDB.Del(this.Id);
 }
        public void Remove(string id)
        {
            var key = GetKeyPrefix(id);

            _client.Del(key);
        }
 public bool DeleteKey(string key)
 {
     csClient.Del(key);
     return(true);
 }
Beispiel #20
0
 public bool Remove(string key)
 {
     return(_client.Del(key) > 0);
 }
 public override void Clear()
 {
     _client.Del(_redisKey);
 }
Beispiel #22
0
 public bool Remove(string key)
 {
     return(csRedisClient.Del(key) > 0);
 }
Beispiel #23
0
 /// <summary>
 /// 删除单个key
 /// </summary>
 /// <param name="key">redis key</param>
 /// <returns>是否删除成功</returns>
 public long KeyDelete(string[] key)
 {
     return(csredis.Del(key));
 }