예제 #1
0
        /// <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));
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
        /// <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());
        }
예제 #6
0
        /// <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);
            }
        }