/// <summary> /// 设置 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="cacheTime"></param> public void Set(string key, object value, TimeSpan cacheTime) { if (value != null) { //序列化,将object值生成RedisValue redisConnection.GetDatabase().StringSet(key, SerializeExtensions.Serialize(value), cacheTime); } }
/// <summary> /// 添加缓存 /// </summary> /// <param name="key">缓存Key</param> /// <param name="value">缓存Value</param> /// <param name="expiresIn">缓存时间</param> /// <returns></returns> public bool Set(string key, object value, int expiresIn = 0) { if (value != null) { //序列化,将object值生成RedisValue if (expiresIn > 0) { return(redisConnection.GetDatabase().StringSet(key, SerializeExtensions.Serialize(value), TimeSpan.FromMinutes(expiresIn))); } else { return(redisConnection.GetDatabase().StringSet(key, SerializeExtensions.Serialize(value))); } } return(false); }