Ejemplo n.º 1
0
            public void Update(string key, string name, DateTime birthday)
            {
                var redisHelper = new StackExchangeRedisHelper();

                conn = redisHelper.SafeConn;//create safe connection
                IDatabase database = conn.GetDatabase();

                var data = redisHelper.Get <User>(database, key);

                if (data == null)
                {
                    Console.WriteLine("No Data");
                }
                else
                {
                    data.Name     = name;
                    data.Birthday = birthday;
                    redisHelper.Add <User>(database, key, data);
                }
            }
Ejemplo n.º 2
0
            public void Insert()
            {
                var seRedisHelper = new StackExchangeRedisHelper();

                conn = seRedisHelper.SafeConn;//create safe connection

                if (conn == null || !conn.IsConnected)
                {
                    Console.WriteLine("No connection is available");
                    return;
                }
                var database = conn.GetDatabase();

                var user1 = new User
                {
                    ID       = 1,
                    Name     = "rico",
                    Birthday = DateTime.Parse("1982-01-01 12:12:12"),
                    Sex      = true
                };

                var user2 = new User
                {
                    ID       = 2,
                    Name     = "sherry",
                    Birthday = DateTime.Parse("1982-02-01 12:12:12"),
                    Sex      = false
                };

                var user3 = new User
                {
                    ID       = 3,
                    Name     = "fifi",
                    Birthday = DateTime.Parse("1982-03-01 12:12:12"),
                    Sex      = false
                };

                //key要注意大小寫
                if (seRedisHelper.Add(database, "User" + user1.ID, user1))
                {
                    Console.WriteLine("User" + user1.ID + " has inserted");
                }
                else
                {
                    Console.WriteLine("User" + user1.ID + " insert failed");
                }
                if (seRedisHelper.Add(database, "User" + user2.ID, user2))
                {
                    Console.WriteLine("User" + user2.ID + " has inserted");
                }
                else
                {
                    Console.WriteLine("User" + user2.ID + " insert failed");
                }
                if (seRedisHelper.Add(database, "User" + user3.ID, user3))
                {
                    Console.WriteLine("User" + user3.ID + " has inserted");
                }
                else
                {
                    Console.WriteLine("User" + user3.ID + " insert failed");
                }
            }