/// <summary> /// 检查指定孩子用户Id是否存在于他的父节点缓存集合中 /// </summary> /// <param name="parentId">父亲用户Id</param> /// <param name="childUserId">孩子用户Id</param> public bool IsInPartOfParentCache(int parentId, int childUserId) { if (GetUserFunc == null) { throw new FException("您未指定查询用户信息的方法"); } string partOfKey = CommonCacheKeys.Build_UserTree_PartOf_Puid_Key(parentId); return(this._easyCache.IsInSet(partOfKey, childUserId.ToString(), db: redisdbIndex)); }
/// <summary> /// 移除指定UserId的孩子集合缓存 /// </summary> public void RemovePartOfParentCache(int userId) { if (GetUserFunc == null) { throw new FException("您未指定查询用户信息的方法"); } string partOfKey = CommonCacheKeys.Build_UserTree_PartOf_Puid_Key(userId); this._easyCache.Remove(partOfKey, db: redisdbIndex); }
/// <summary> /// 把指定的孩子UserId从指定父亲的孩子集合缓存里移除 /// </summary> /// <param name="parentId">父亲用户Id</param> /// <param name="childUserId">孩子用户Id</param> public void RemoveMemberFromPartOfParentCache(int parentId, int childUserId) { if (GetUserFunc == null) { throw new FException("您未指定查询用户信息的方法"); } string partOfKey = CommonCacheKeys.Build_UserTree_PartOf_Puid_Key(parentId); this._easyCache.SetRemove(partOfKey, childUserId.ToString(), db: redisdbIndex); }
/// <summary> /// 查找指定用户的【直接】孩子个数(不包括自己) /// </summary> public long FindDirectChildCount(int parentId) { if (GetUserFunc == null) { throw new FException("您未指定查询用户信息的方法"); } //再找出直接孩子的树节点 string partOfParentKey = CommonCacheKeys.Build_UserTree_PartOf_Puid_Key(parentId); //【模式匹配】找出直接孩子的树节点Key long count = this._easyCache.GetSetLength(partOfParentKey, db: redisdbIndex); return(count); }
/// <summary> /// 查找指定用户的【直接】孩子UserId集合(不包括自己) /// </summary> public List <int> FindDirectChildUserId(int parentId) { if (GetUserFunc == null) { throw new FException("您未指定查询用户信息的方法"); } //再找出直接孩子的树节点 string partOfParentKey = CommonCacheKeys.Build_UserTree_PartOf_Puid_Key(parentId); //【模式匹配】找出直接孩子的树节点Key var childUserIdList = this._easyCache.GetSetList(partOfParentKey, db: redisdbIndex) ?? new List <string>(); return(childUserIdList.Select(x => int.Parse(x)).ToList()); }
/// <summary> /// 把指定的孩子UserId添加到指定父亲的孩子集合缓存里 /// </summary> /// <param name="parentId">父亲用户Id</param> /// <param name="childUserId">孩子用户Id</param> public void AddToPartOfParentCache(int parentId, int childUserId) { if (GetUserFunc == null) { throw new FException("您未指定查询用户信息的方法"); } string partOfKey = CommonCacheKeys.Build_UserTree_PartOf_Puid_Key(parentId); this._easyCache.SetAdd(partOfKey, childUserId.ToString(), db: redisdbIndex); //为了防止数据没有添加到redis,这里做一次检查,并且再补偿一次,记下记录以便跟踪。 if (!IsInPartOfParentCache(parentId, childUserId)) { logger.Fatal($"PartOfParentCache:出现添加异常。parentId={parentId},childUserId={childUserId}"); this._easyCache.SetAdd(partOfKey, childUserId.ToString(), db: redisdbIndex); } }