Redis Combat (iv)

Source: Internet
Author: User

The Web. config program is configured, and the above configuration information can be read and managed through C # code.

Next, you can write the data for Redis. In Redis, you can save single and multiple pieces of data with store and Storeall, and the code in C # is as follows:
 protected voidBtnopendb_click (Objectsender, EventArgs e) {            //System.Diagnostics.Process.Start ("D:\\redis\\redis-server.exe"); //Lblshow.text = "Redis is open!" ";            using(varRedisclient =redismanager.getclient ()) {                varuser = Redisclient.gettypedclient<user>(); if(User. GetAll (). Count >0) user.                DeleteAll (); varQiujialong =NewUser {Id=user. Getnextsequence (), Name="Qiujialong", Job=NewJob {Position =". NET" }                }; varChenxingxing =NewUser {Id=user. Getnextsequence (), Name="chenxingxing", Job=NewJob {Position =". NET" }                }; varLuwei =NewUser {Id=user. Getnextsequence (), Name="Luwei", Job=NewJob {Position =". NET" }                }; varZhourui =NewUser {Id=user. Getnextsequence (), Name="Zhourui", Job=NewJob {Position ="Java" }                }; varUsertostore =NewList<user>{qiujialong, chenxingxing, Luwei, Zhourui}; User.                              StoreAll (Usertostore); Lblshow.text="currently in total:"+ user. GetAll (). Count.tostring () +"people! "; }        }

2 , save a single piece of data

protected voidBtninsert_click (Objectsender, EventArgs e) {            if(!string. IsNullOrEmpty (txtname.text) &&!string. IsNullOrEmpty (Txtposition.text)) {using(varRedisclient =redismanager.getclient ()) {                    varuser = Redisclient.gettypedclient<user>(); varNewUser =NewUser {Id=user. Getnextsequence (), Name=txtName.Text, Job=NewJob {Position =Txtposition.text}}; User.                                       Store (NewUser); if(User. GetAll (). Count >0)                    {                        varHtmlstr =string.                        Empty; foreach(varUinchuser. GetAll ()) {Htmlstr+="<li>id="+ U.id +"&nbsp;&nbsp; Name:"+ U.name +"&nbsp;&nbsp; Department:"+ U.job.position +"</li>"; } Lblpeople.text=Htmlstr; } Lblshow.text="currently in total:"+ user. GetAll (). Count.tostring () +"people! "; }            }        }

Redis Combat (iv)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.