public void Exist_With_Valid_Object_Should_Return_The_Correct_Instance() { var values = Builder <TestClass <string> > .CreateListOfSize(2) .Build(); values.ForEach(x => Db.StringSet(x.Key, x.Value)); Assert.True(Sut.Exists(values[0].Key)); }
/// <summary> /// /// </summary> public bool Update <T>(string Key, T Entity) where T : class { if (_bUseLocalCache) { Utility.Cache.Clear(Key); Utility.Cache.Store <T>(Entity, Key, DateTime.Now.AddMinutes(60), true); return(true); } if (_Cache.Exists(Key)) { if (_Cache.Remove(Key)) { var entity = Serialise(Entity); return(_Cache.Add(Key, entity)); } } return(false); }
/// <summary> /// 缓存用户好友列表 /// </summary> /// <param name="userId">用户ID</param> /// <param name="list">好友列表 1,2,3,4 (不知道好友列表长度会不会超过限制,如果超过限制,就不能用string存储了)</param> /// <returns>返回是否成功 true false</returns> public bool SetUserFriendList(int userId, string list) { if (string.IsNullOrEmpty(list)) { return(true); } //用户好友列表key var key = string.Format(LayIMConst.LayIM_All_UserFriends, userId); //如果key已经存在,先remove掉 if (cacheClient.Exists(key)) { cacheClient.Remove(key); } //一天过期 return(cacheClient.Add <string>(key, list, DateTimeOffset.Now.AddDays(1))); }
public bool Exists(string key) => Client.Exists(key);
public bool IsSet(string key) { return(_retryPolicy.ExecuteAction(() => _cacheClient.Exists(key))); }