Cache frame--redis (i)

Source: Internet
Author: User
Tags object serialization



one, the installation of the service side


Service side I use redis64-2.6.12.1, version is relatively low, because 2.8 is not on, probably because their computer is Windows reason it.


After the decompression is complete,


Enter into this folder, enter: Redis-server.exe redis.conf, after the service opened successfully, this will be:






Two, installation of the client program


Like memcached, we can also operate the cache by means of CMD, which can be used in the client program.

in the. NET project, I'm using servicestack.redis.3.9.29.0.




Three, simple demo example


Using system;using system.collections.generic;using system.linq;using system.text;using ServiceStack.Common;using        Servicestack.serviceinterface;using servicestack.redis;using Servicestack.text;namespace TestRedis{class Program {        static Redisclient Redis = new Redisclient ("127.0.0.1", 6379); static void Main (string[] args) {//Adds a list of characters to Redis list<string> storemembers = new list&            lt;string>{"One", "one", "three"};            Storemembers.foreach (X=>redis.additemtolist ("Additemtolist", x));            Gets the value set corresponding to the specified key var members = Redis.getallitemsfromlist ("Additemtolist"); Members.            ForEach (S=>console.writeline ("additemtolist:" +s));            Gets the specified index location data var item = redis.getitemfromlist ("Additemtolist", 2);            Console.WriteLine (item);            Remove data var list = redis.lists["Additemtolist"]; List. Clear ();//Clear list. Remove ("both");//Remove the specified key value//Storage Object (JSON serialization method) it is much more efficient than the object serialization method Redis.set<userinfo> ("UserInfo", new UserInfo () {username= "LHC", age=12})            ;            UserInfo UserInfo = redis.get<userinfo> ("UserInfo");            Console.WriteLine ("Name=" +userinfo.username+ "; age=" +userinfo.age);            Store value type data redis.set<int> ("My_age", 12);            int age = redis.get<int> ("My_age");            Console.WriteLine ("age=" + age);            The object serialization method stores var ser = new ServiceStack.Redis.Support.ObjectSerializer (); BOOL Result=redis.set<byte[]> ("UserInfo2", Ser.            Serialize (New UserInfo () {username= "PBC", age=27})); UserInfo Userinfo2=ser.            Deserialize (redis.get<byte[]> ("UserInfo2")) as UserInfo;            Console.WriteLine ("Name=" +userinfo2.username+ "; age=" +userinfo2.age); also supports list list<userinfo> userinfolist = new List<userinfo> {new userinfo{username= "L HCCC ", age=22}, new UserinFo{username= "Bcss", age=100}}; Redis.set<byte[]> ("Userinfolist_serialize", Ser.            Serialize (userinfolist)); list<userinfo> userlist = ser.            Deserialize (redis.get<byte[]> ("Userinfolist_serialize")) as list<userinfo>;                Userlist.foreach (U = {Console.WriteLine ("Name=" +u.username+ "; age=" +u.age);            }                );        Console.readkey (); }    }}



personally, Redis supports more data types than memcached, and memory data can be persisted, performance is good, about the specific technical options analysis, see next month.







Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Cache frame--redis (i)

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.