Iv. write data in the C # Redis Combat (iii) We have configured the Web. config program and can read and manage the above configuration information 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:
1. Save more than one piece of data
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 +" Name:"+ U.name +" Department:"+ U.job.position +"</li>"; } Lblpeople.text=Htmlstr; } Lblshow.text="currently in total:"+ user. GetAll (). Count.tostring () +"people! "; } } }
:
If you want to reprint, please specify the source, this series of blog sample program
http://blog.csdn.net/qiujialongjjj/article/details/17221631
C # Redis Combat (iv)