Beispiel #1
0
        public void RedisInsertManyTest()
        {
            RedisServer r = new RedisServer("localhost");

            r.Db = 3;
            r.KeyDelete("hash");
            r.HashSetMany("hash", new Dictionary <string, string> {
                { "1", "2" }, { "2", "3" }
            });
            var hash = r.HashGetAll("hash");

            Assert.AreEqual(hash.Length, 2);
            Assert.AreEqual("2", r.HashGet("hash", "1"));
            Assert.AreEqual("3", r.HashGet("hash", "2"));
            r.KeyDelete("hash");

            r.KeyDelete("set");
            r.SetAddManay("set", new List <string> {
                "1", "2", "3"
            });
            var set = r.SetMembers("set");

            Assert.AreEqual(set.Count, 3);
            Assert.AreEqual("1", set[0]);
            Assert.AreEqual("2", set[1]);
            Assert.AreEqual("3", set[2]);
            r.KeyDelete("set");


            r.KeyDelete("list");
            r.ListRightPushMany("list", new List <string> {
                "1", "2", "3", "4", "5"
            });
            Assert.AreEqual(5, r.ListLength("list"));
            Assert.AreEqual("1", r.ListLeftPop("list"));
            Assert.AreEqual("5", r.ListRightPop("list"));
            Assert.AreEqual("4", r.ListRightPop("list"));
            Assert.AreEqual("2", r.ListLeftPop("list"));
            r.KeyDelete("list");

            r.Dispose();
        }
        public void RedisInsertManyTest()
        {
            RedisServer r = new RedisServer("localhost");

            r.Db = 3;
            r.KeyDelete("hash");
            r.HashSetMany("hash", new Dictionary<string, string> { { "1", "2" }, { "2", "3" } });
            var hash = r.HashGetAll("hash");
            Assert.AreEqual(hash.Length, 2);
            Assert.AreEqual("2", r.HashGet("hash", "1"));
            Assert.AreEqual("3", r.HashGet("hash", "2"));
            r.KeyDelete("hash");

            r.KeyDelete("set");
            r.SetAddManay("set", new List<string> { "1", "2", "3" });
            var set = r.SetMembers("set");
            Assert.AreEqual(set.Count, 3);
            Assert.AreEqual("1", set[0]);
            Assert.AreEqual("2", set[1]);
            Assert.AreEqual("3", set[2]);
            r.KeyDelete("set");

            r.KeyDelete("list");
            r.ListRightPushMany("list", new List<string> { "1", "2", "3", "4", "5" });
            Assert.AreEqual(5, r.ListLength("list"));
            Assert.AreEqual("1", r.ListLeftPop("list"));
            Assert.AreEqual("5", r.ListRightPop("list"));
            Assert.AreEqual("4", r.ListRightPop("list"));
            Assert.AreEqual("2", r.ListLeftPop("list"));
            r.KeyDelete("list");

            r.Dispose();
        }
        public void RedisBaseTest()
        {
            RedisServer r = new RedisServer("localhost");

            r.Db = 3;

            #region set

            long i;
            r.SetLength("a");
            r.SetAdd("foo", "bar");
            r.FlushDb();

            Assert.IsTrue((i = r.SetLength("foo")) == 0, "there should be no keys but there were {0}", i);
            r.SetAdd("foo", "bar");
            Assert.IsTrue((i = r.SetLength("foo")) == 1, "there should be one key but there were {0}", i);
            r.SetAdd("foo bär", "bär foo");
            r.SetAdd("foo", "bär foo");
            Assert.IsTrue((i = r.SetLength("foo")) == 2, "there should be two keys but there were {0}", i);

            Assert.IsTrue(r.TypeOf("foo") == KeyType.Set, "type is not string");
            r.SetAdd("bar", "foo");

            Assert.IsTrue(r.SetContains("bar", "foo"));

            var mems = r.SetMembers("foo");
            Assert.AreEqual("bar", mems[0]);
            Assert.AreEqual("bär foo", mems[1]);

            r.SetRemove("foo", "bar");
            mems = r.SetMembers("foo");
            Assert.AreEqual("bär foo", mems[0]);
            Assert.AreEqual(1, mems.Count);

            string item = r.SetPop("foo");
            Assert.AreEqual("bär foo", item);
            Assert.AreEqual(0, r.SetLength("foo"));

            #endregion

            #region hasset

            r.HashSet("set", "a", "a");
            r.HashSet("set", "b", "b");
            r.HashSet("set", "c", "c");
            var hash = r.HashGetAll("set");
            Assert.AreEqual(hash.Length, 3);

            r.HashDelete("set", "a");
            hash = r.HashGetAll("set");
            Assert.AreEqual(hash.Length, 2);

            Assert.AreEqual(true, r.HashExists("set", "b"));
            Assert.AreEqual("b", r.HashGet("set", "b"));
            Assert.AreEqual(2, r.HashLength("set"));

            #endregion

            #region storedset

            r.SortedSetAdd("sortedset", "a", 0L);
            r.SortedSetAdd("sortedset", "b", 0L);
            r.SortedSetAdd("sortedset", "c", 0L);
            r.SortedSetAdd("sortedset", "d", 0L);
            Assert.AreEqual(4, r.SortedSetLength("sortedset"));
            r.SortedSetRemove("sortedset", "a");
            Assert.AreEqual(3, r.SortedSetLength("sortedset"));

            string[] sr = r.SortedSetRangeByRank("sortedset", 0, 2);
            Assert.AreEqual("b", sr[0]);
            Assert.AreEqual("c", sr[1]);
            Assert.AreEqual("d", sr[2]);

            #endregion

            #region list

            r.ListLeftPush("list", "1");
            r.ListLeftPush("list", "2");
            r.ListLeftPush("list", "3");
            r.ListLeftPush("list", "4");
            r.ListRightPush("list", "5");
            Assert.AreEqual(5, r.ListLength("list"));
            Assert.AreEqual("4", r.ListLeftPop("list"));
            Assert.AreEqual("5", r.ListRightPop("list"));
            Assert.AreEqual("1", r.ListRightPop("list"));
            Assert.AreEqual("3", r.ListLeftPop("list"));

            #endregion

            #region locker

            r.LockTake("locker", DateTime.Now.ToString(), new TimeSpan(0, 0, 0, 30));
            #endregion

            r.FlushDb();
            r.Dispose();
        }
Beispiel #4
0
        public void RedisBaseTest()
        {
            RedisServer r = new RedisServer("localhost");

            r.Db = 3;

            #region set

            long i;
            r.SetLength("a");
            r.SetAdd("foo", "bar");
            r.FlushDb();

            Assert.IsTrue((i = r.SetLength("foo")) == 0, "there should be no keys but there were {0}", i);
            r.SetAdd("foo", "bar");
            Assert.IsTrue((i = r.SetLength("foo")) == 1, "there should be one key but there were {0}", i);
            r.SetAdd("foo bär", "bär foo");
            r.SetAdd("foo", "bär foo");
            Assert.IsTrue((i = r.SetLength("foo")) == 2, "there should be two keys but there were {0}", i);

            Assert.IsTrue(r.TypeOf("foo") == KeyType.Set, "type is not string");
            r.SetAdd("bar", "foo");

            Assert.IsTrue(r.SetContains("bar", "foo"));

            var mems = r.SetMembers("foo");
            Assert.AreEqual("bar", mems[0]);
            Assert.AreEqual("bär foo", mems[1]);

            r.SetRemove("foo", "bar");
            mems = r.SetMembers("foo");
            Assert.AreEqual("bär foo", mems[0]);
            Assert.AreEqual(1, mems.Count);

            string item = r.SetPop("foo");
            Assert.AreEqual("bär foo", item);
            Assert.AreEqual(0, r.SetLength("foo"));

            #endregion

            #region hasset

            r.HashSet("set", "a", "a");
            r.HashSet("set", "b", "b");
            r.HashSet("set", "c", "c");
            var hash = r.HashGetAll("set");
            Assert.AreEqual(hash.Length, 3);

            r.HashDelete("set", "a");
            hash = r.HashGetAll("set");
            Assert.AreEqual(hash.Length, 2);

            Assert.AreEqual(true, r.HashExists("set", "b"));
            Assert.AreEqual("b", r.HashGet("set", "b"));
            Assert.AreEqual(2, r.HashLength("set"));

            #endregion

            #region storedset

            r.SortedSetAdd("sortedset", "a", 0L);
            r.SortedSetAdd("sortedset", "b", 0L);
            r.SortedSetAdd("sortedset", "c", 0L);
            r.SortedSetAdd("sortedset", "d", 0L);
            Assert.AreEqual(4, r.SortedSetLength("sortedset"));
            r.SortedSetRemove("sortedset", "a");
            Assert.AreEqual(3, r.SortedSetLength("sortedset"));

            string[] sr = r.SortedSetRangeByRank("sortedset", 0, 2);
            Assert.AreEqual("b", sr[0]);
            Assert.AreEqual("c", sr[1]);
            Assert.AreEqual("d", sr[2]);

            #endregion


            #region list

            r.ListLeftPush("list", "1");
            r.ListLeftPush("list", "2");
            r.ListLeftPush("list", "3");
            r.ListLeftPush("list", "4");
            r.ListRightPush("list", "5");
            Assert.AreEqual(5, r.ListLength("list"));
            Assert.AreEqual("4", r.ListLeftPop("list"));
            Assert.AreEqual("5", r.ListRightPop("list"));
            Assert.AreEqual("1", r.ListRightPop("list"));
            Assert.AreEqual("3", r.ListLeftPop("list"));

            #endregion

            #region locker

            r.LockTake("locker", DateTime.Now.ToString(), new TimeSpan(0, 0, 0, 30));
            #endregion

            r.FlushDb();
            r.Dispose();
        }