Esempio n. 1
0
        /// <summary>
        /// 异步重置缓存数据过期时间
        /// </summary>
        /// <param name="pattern">通配符</param>
        /// <param name="addSeconds">更新的过期时间</param>
        /// <returns>是否成功</returns>
        public async Task <bool> ResetAllExpireTimeAsync(string pattern, int addSeconds = 3600)
        {
            try
            {
                var keys = await _redisClient.KeysAsync(pattern);

                if (keys == null || keys.Length == 0)
                {
                    return(false);
                }

                foreach (var key in keys)
                {
                    await _redisClient.ExpireAtAsync(key, DateTime.Now.AddSeconds(addSeconds));
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }