/// <summary> /// 删除缓存 /// </summary> /// <param name="key">缓存key</param> /// <returns></returns> public int Delete(string key) { key = CacheUtils.getPrefixKey(key); return(db.KeyDelete(key) ? 1 : 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)); }
/// <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())); }
/// <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())); }