示例#1
0
 /// <summary>
 /// 删除缓存
 /// </summary>
 /// <param name="key">缓存key</param>
 /// <returns></returns>
 public int Delete(string key)
 {
     key = CacheUtils.getPrefixKey(key);
     return(db.KeyDelete(key) ? 1 : 0);
 }
示例#2
0
        /// <summary>
        /// 写入缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="timeSpan"></param>
        /// <returns></returns>
        public bool Set <T>(string key, T value, TimeSpan timeSpan)
        {
            key = CacheUtils.getPrefixKey(key);

            return(db.StringSet(key, CacheUtils.ConvertJson(value), timeSpan));
        }
示例#3
0
 /// <summary>
 /// 写入缓存,设置过期秒数
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="key">缓存key</param>
 /// <param name="value">缓存值</param>
 /// <param name="expiresSecond">过期秒数</param>
 /// <returns>返回值,表示:是否写入成功</returns>
 public bool Set <T>(string key, T value, int expiresSecond)
 {
     key = CacheUtils.getPrefixKey(key);
     return(db.StringSet(key, CacheUtils.ConvertJson(value), DateTime.Now.AddSeconds(expiresSecond) - new DateTime()));
 }
示例#4
0
 /// <summary>
 /// 写入缓存,设置过期时间点
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="key">缓存key</param>
 /// <param name="value">缓存值</param>
 /// <param name="expiresAt">过期时间点</param>
 /// <returns>返回值,表示:是否写入成功</returns>
 public bool Set <T>(string key, T value, DateTime expiresAt)
 {
     key = CacheUtils.getPrefixKey(key);
     return(db.StringSet(key, CacheUtils.ConvertJson(value), expiresAt - new DateTime()));
 }