ServiceStack. Redis, redis

Source: Internet
Author: User

ServiceStack. Redis, redis
What is Redis?

First, briefly describe what Redis is.

Redis is an open-source, network-supported, memory-based, key-Value Pair storage database written in ansi c. Redis development was sponsored by Pivotal since May 2013. Prior to that, its development was sponsored by VMware. Redis is the most popular key-Value Pair storage database, according to the data of the monthly ranking website DB-Engines.com.

For more details, see:

ServiceStack for Redis operations
Public static void Main (string [] args) {var Redis = new RedisClient ("Wagner. 0.0.1", 6379 ); // redis service IP address and port # region insert var storeMembers = new List <string> {"aaa", "bbb", "ccc"}; storeMembers. forEach (x => Redis. addItemToList ("additemtolist", x); // Note: You can also directly use the AddRangeToList method to load a set of data into Redis. addRangeToList ("additemtolist", storeMembers); # endregion # region get var members = Redis. getAllItemsFromList ("additemtolist"); members. forEach (s => Console. writeLine ("additemtolist:" + s); Console. writeLine (Redis. getItemFromList ("additemtolist", 2); # endregion # region delete var list = Redis. lists ["additemtolist"]; list. clear (); // Clear the list. remove ("two"); // Remove the list of specified key values. removeAt (2); // remove the data at the specified index position # endregion # region object Redis. set ("userinfo", new UserInfo () {UserName = "zhangsan", Age = 11}); UserInfo userinfo = Redis. get <UserInfo> ("userinfo"); Console. writeLine (userinfo. userName); Redis. set <int> ("my_age", 12); // or Redis. set ("my_age", 12); Console. writeLine (Redis. get <int> ("my_age"); # endregion var ser = new ObjectSerializer (); // located in namespace ServiceStack. redis. support; # region serialized bool result = Redis. set <byte []> ("userinfo", ser. serialize (new UserInfo () {UserName = "longyi", Age = 12}); UserInfo userinfo = ser. deserialize (Redis. get <byte []> ("userinfo") as UserInfo; Console. writeLine (userinfo. userName); # endregion // list Redis is also supported. set <byte []> ("userinfolist_serialize", ser. serialize (userinfoList); # region Server Load balancer PooledRedisClientManager prcm = CreateManager (new string [] {"10.0.4.210: 6379"}, new string [] {"10.0.4.210: 6379 "}); list <UserInfo> userinfoList = new List <UserInfo> (); userinfoList. add (new UserInfo () {UserName = "pool_daizhj", Age = 1}); userinfoList. add (new UserInfo () {UserName = "pool_daizhj1", Age = 2}); // obtain 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 static PooledRedisClientManager CreateManager (string [] readWriteHosts, string [] readOnlyHosts) {// read/write splitting is supported, and the returned load is new PooledRedisClientManager (readWriteHosts, new RedisClientManagerConfig {MaxWritePoolSize = 5, // "write" link pool connection count MaxReadPoolSize = 5, // "write" link pool connection count AutoStart = true ,});}

 

 

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.