Пример #1
0
        public void ZaddXxTest()
        {
            var key = $"{nameof(ZaddXxTest)}Key";

            string result;

            result = _client.Zadd(key, new[] { "1", "a", "2", "b", "3", "c" });
            Assert.AreEqual("3", result);

            result = _client.ZaddXx(key, new[] { "2", "c", "4", "d" });
            Assert.AreEqual("0", result);

            result = _client.ZrangeWithScores(key, 0, -1);
            Assert.AreEqual("a 1 b 2 c 2", result);
        }
        public object Execute(string[] args)
        {
            if (args.Length < 4)
            {
                throw new ArgumentException("(error) wrong number of arguments");
            }

            var key = args[1];

            Func <string, int?> ToInt = (string input) => Convert.ToInt32(input);

            var start = ToInt.SafeExecution(args[2]);
            var stop  = ToInt.SafeExecution(args[3]);

            if (!start.HasValue || !stop.HasValue)
            {
                throw new ArgumentException("(error) ERR value is not an integer or out of range");
            }

            object result;

            if (args.Length == 4)
            {
                result = _client.Zrange(key, start.Value, stop.Value);
            }
            else if (args.Length == 5)
            {
                var withScores = args[4];
                if (withScores.ToUpperInvariant() != "WITHSCORES")
                {
                    throw new ArgumentException("(error) ERR Syntax error");
                }

                result = _client.ZrangeWithScores(key, start.Value, stop.Value);
            }
            else
            {
                throw new ArgumentException("(error) wrong number of arguments");
            }

            return(result);
        }