Servicestack operating Redis

Source: Internet
Author: User

TaticvoidMain (string[] args) {             varRedis =NewRedisclient ("127.0.0.1",6379);//Redis Service IP and Ports            #region=insert=varStoremembers =Newlist<string> {"JJ","Lihui","cc" }; Storemembers.foreach (x= Redis.additemtolist ("additemtolist", x)); //Note: You can also directly use the Addrangetolist method to load a set of data such as:Redis.addrangetolist ("additemtolist", storemembers); #endregion              #region=get=varMembers = Redis.getallitemsfromlist ("additemtolist"); Members. ForEach (S= Console.WriteLine ("additemtolist:"+s)); Console.WriteLine (Redis.getitemfromlist ("additemtolist",2)); #endregion              #region=delete=varList = redis.lists["additemtolist"]; List. Clear ();//ClearList. Remove (" Both");//Remove the specified key valueList. RemoveAt (2);//To remove the specified index location data           #endregion             #region=object=Redis.set ("UserInfo",NewUserInfo () {UserName ="John Doe", age = $ }); UserInfo UserInfo= Redis.get<userinfo> ("UserInfo"); Console.WriteLine (UserInfo.               UserName); Redis.set<int> ("My_age", A);//or Redis.set ("My_age", 12); Console.WriteLine (redis.get<int> ("My_age")); #endregion               varSer =NewObjectserializer ();//located in namespace ServiceStack.Redis.Support;            #region= Serialization =BOOLresult = redis.set<byte[]> ("UserInfo", Ser. Serialize (NewUserInfo () {UserName ="Zhang San", age = A })); UserInfo UserInfo= Ser. Deserialize (redis.get<byte[]> ("UserInfo")) asUserInfo; Console.WriteLine (UserInfo.             UserName); #endregion               //also support listredis.set<byte[]> ("userinfolist_serialize", Ser.              Serialize (userinfolist)); #region= Load Balancer =Pooledredisclientmanager PRCM= Createmanager (New string[] {"10.0.4.210:6379"},New string[] {"10.0.4.210:6379" }); List<UserInfo> userinfolist =NewList<userinfo>(); Userinfolist.add (NewUserInfo () {UserName ="POOL_DAIZHJ", age =1 }); Userinfolist.add (NewUserInfo () {UserName ="pool_daizhj1", age =2 }); //get a link from the pool:             using(Iredisclient Redis2 =PRCM. Getclient ()) {Redis2.set ("userinfolist", userinfolist); List<UserInfo> userlist = redis2.get<list<userinfo>> ("userinfolist"); }              #endregion  Console.ReadLine (); }          Public StaticPooledredisclientmanager Createmanager (string[] readwritehosts,string[] readonlyhosts) {             //supports read-write separation, balanced load           return NewPooledredisclientmanager (readwritehosts, Readonlyhosts,NewRedisclientmanagerconfig {maxwritepoolsize=5,//number of "write" link pool linksMaxreadpoolsize =5,//number of "write" link pool linksAutoStart =true,             }); }  

Servicestack operating Redis

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.