Exemple #1
0
        public void Hash()
        {
            //无序字典
            string guid     = "Hash";
            var    userInfo = new UserInfo_StringSetDto
            {
                Id      = "1",
                Name    = "张小三",
                Phone   = "13500000001",
                Address = new Address
                {
                    Province   = "上海",
                    City       = "",
                    Town       = "",
                    PostalCode = ""
                }
            };

            redisHelper.HashSet <string>(guid, nameof(userInfo.Id), "1");
            redisHelper.HashSet <string>(guid, nameof(userInfo.Id), "1");
            redisHelper.HashSet <string>(guid, nameof(userInfo.Id), "1");
            redisHelper.HashSet <string>(guid, nameof(userInfo.Name), userInfo.Name);
            redisHelper.HashSet <string>(guid, nameof(userInfo.Phone), userInfo.Phone);
            redisHelper.HashSet <Address>(guid, nameof(userInfo.Address), userInfo.Address);

            var name = redisHelper.HashGet <string>(guid, nameof(userInfo.Name));
        }
Exemple #2
0
        public void Zset()
        {
            //有序列表

            /*
             *      一方面它是一个 set,保证了内部
             *      value 的唯一性,另一方面它可以给每个 value 赋予一个 score,代表这个 value 的排序权
             *      重。它的内部实现用的是一种叫着「跳跃列表」的数据结构。
             */
            string guid      = "SortedSet";
            var    userInfo1 = new UserInfo_StringSetDto
            {
                Id      = "1",
                Name    = "张小三",
                Phone   = "13500000001",
                Address = new Address
                {
                    Province   = "上海",
                    City       = "",
                    Town       = "",
                    PostalCode = "1"
                }
            };

            var userInfo2 = new UserInfo_StringSetDto
            {
                Id      = "1",
                Name    = "张小三",
                Phone   = "13500000001",
                Address = new Address
                {
                    Province   = "上海",
                    City       = "",
                    Town       = "",
                    PostalCode = "1"
                }
            };

            var userInfo3 = new UserInfo_StringSetDto
            {
                Id      = "1",
                Name    = "张小三",
                Phone   = "13500000001",
                Address = new Address
                {
                    Province   = "上海",
                    City       = "",
                    Town       = "",
                    PostalCode = "1"
                }
            };

            redisHelper.SortedSetAdd <UserInfo_StringSetDto>(guid, userInfo1, 1);
            redisHelper.SortedSetAdd <UserInfo_StringSetDto>(guid, userInfo2, 2);
            redisHelper.SortedSetAdd <UserInfo_StringSetDto>(guid, userInfo3, 3);

            var sortedSetResult = Database.SortedSetRangeByScore(guid);
        }
Exemple #3
0
        public void String()
        {
            var userInfo = new UserInfo_StringSetDto
            {
                Id      = Guid.NewGuid().ToString(),
                Name    = "张小三",
                Phone   = "13500000001",
                Address = new Address
                {
                    Province   = "上海",
                    City       = "",
                    Town       = "",
                    PostalCode = ""
                }
            };
            var serializeData = JsonConvert.SerializeObject(userInfo);
            var result        = redisHelper.StringSet("String", serializeData);

            Assert.True(result);
            var result1 = redisHelper.StringGet <UserInfo_StringSetDto>("String");
        }
Exemple #4
0
        public void Set()
        {
            var userInfo = new UserInfo_StringSetDto
            {
                Id      = Guid.NewGuid().ToString(),
                Name    = "张小三",
                Phone   = "13500000001",
                Address = new Address
                {
                    Province   = "上海",
                    City       = "",
                    Town       = "",
                    PostalCode = ""
                }
            };

            var serializeData = JsonConvert.SerializeObject(userInfo);

            Database.SetAdd("Set", serializeData);
            for (int i = 0; i < Database.SetLength("Set"); i++)
            {
                var cc = Database.SetPop("Set");
            }
        }