Esempio n. 1
0
        /// <summary>
        /// 按高低位两个数字组合范围取出SortedSet中的ID
        /// </summary>
        /// <param name="setId">Key的二进制</param>
        /// <param name="h">返回的高位</param>
        /// <param name="l">返回的低位</param>
        /// <returns>true表示成功取到值</returns>
        /// <remarks>l或h值如果大于0xFFFFFF将被截断</remarks>>
        public List <long> ZRangeByScore(byte[] setId, long h, long l)
        {
            var vl = string.Concat(h & 0xFFFFFF, '.', l & 0xFFFFFF).ToUtf8Bytes();

            var command = new[] { Commands.ZRangeByScore, setId, vl, vl };
            var bytes   = this.SendExpectMultiData(command);

            if (bytes == null || bytes.Length == 0)
            {
                return(new List <long>());
            }
            return(bytes.Select(bf => bf.Length == 4 ? ByteCommond.BytesToInt(bf) : ByteCommond.BytesToLong(bf)).ToList());
        }
Esempio n. 2
0
        /// <summary>
        /// 读取SortedSet的分值(高低位两个数字)
        /// </summary>
        /// <param name="setId">Key的二进制</param>
        /// <param name="dataId">Id的二进制</param>
        /// <param name="h">返回的高位</param>
        /// <param name="l">返回的低位</param>
        /// <returns>true表示成功取到值</returns>
        public bool ZScore(byte[] setId, byte[] dataId, out int h, out int l)
        {
            if (setId == null)
            {
                throw new ArgumentNullException("setId");
            }
            var command = new[] { Commands.ZScore, setId, dataId };

            h = 0;
            if (!this.SendCommand(command))
            {
                Status    = -1;
                LastError = string.Join(" ", "ZScore", Encoding.UTF8.GetString(setId), ByteCommond.BytesToLong(dataId));
                l         = 0;
                return(false);
            }
            var line = ReadSingleLine();

            if (line.type != 2)
            {
                Status = 2;
                l      = 0;
                return(false);
            }
            StringBuilder sb = new StringBuilder();

            foreach (char by in line.bValue)
            {
                if (by == '.')
                {
                    h = int.Parse(sb.ToString());
                    sb.Clear();
                }
                else
                {
                    sb.Append(by);
                }
            }
            l = int.Parse(sb.ToString());
            return(true);
        }