コード例 #1
0
ファイル: WebForm1.aspx.cs プロジェクト: fomin-zhu/RedisDemo
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtName.Text) && !string.IsNullOrEmpty(txtPosition.Text))
            {
                using (var redisClient = RedisManager.GetClient())
                {
                    var user = redisClient.As<User>();

                    var newUser = new User
                    {
                        Id = user.GetNextSequence(),
                        Name = txtName.Text,
                        Job = new Job { Position = txtPosition.Text }
                    };
                    var userList = new List<User> { newUser };
                    user.StoreAll(userList);

                    if (user.GetAll().Count > 0)
                    {
                        var htmlStr = string.Empty;
                        foreach (var u in user.GetAll())
                        {
                            htmlStr += "<li>ID=" + u.Id + "&nbsp;&nbsp;姓名:" + u.Name + "&nbsp;&nbsp;所在部门:" + u.Job.Position + "</li>";
                        }
                        lblPeople.Text = htmlStr;
                    }
                    lblShow.Text = "目前共有:" + user.GetAll().Count.ToString() + "人!";
                }
            }
        }
コード例 #2
0
ファイル: WebForm1.aspx.cs プロジェクト: fomin-zhu/RedisDemo
        protected void btnOpenDB_Click(object sender, EventArgs e)
        {
            using (var redisClient = RedisManager.GetClient())
            {
                var user = redisClient.As<User>();

                if (user.GetAll().Count > 0)
                    user.DeleteAll();

                var qiujialong = new User
                {
                    Id = user.GetNextSequence(),
                    Name = "qiujialong",
                    Job = new Job { Position = ".NET" }
                };
                var chenxingxing = new User
                {
                    Id = user.GetNextSequence(),
                    Name = "chenxingxing",
                    Job = new Job { Position = ".NET" }
                };
                var luwei = new User
                {
                    Id = user.GetNextSequence(),
                    Name = "luwei",
                    Job = new Job { Position = ".NET" }
                };
                var zhourui = new User
                {
                    Id = user.GetNextSequence(),
                    Name = "zhourui",
                    Job = new Job { Position = "Java" }
                };

                var userToStore = new List<User> { qiujialong, chenxingxing, luwei, zhourui };
                user.StoreAll(userToStore);

                Thread.Sleep(3000);

                lblShow.Text = "目前共有:" + user.GetAll().Count.ToString() + "人!";
            }
        }