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