Servicestack.redis's iredistypedclient 04_ turn

Source: Internet
Author: User

Iredistypedclient

The Iredistypedclient class is equivalent to a strongly typed version of Iredicclient, and its methods and properties are mostly similar to iredisclient.

It supports the powerful class that uses LINQ queries in Redis, which itself is a generic, iredisclient generic method as a Get object.

The method is prototyped as follows:

    Iredistypedclient<t> as<t> ();

  1. Ientitystore<t> Interface Content

Where iredistypedclient this class implements the interface ientitystore<t>, the interface requires the following features:

Method Description
Delete Delete a record based on an entity
DeleteAll Delete all
Deletebyid Delete a record by ID
Deletebyids Delete multiple records based on multiple IDs entered
GetAll Get all records of this type
GetById Get a record by ID
Getbyids Get multiple records based on multiple IDs entered
Store Adds a record based on the entity passed in
StoreAll Add multiple records based on an incoming entity collection

Examples of LINQ queries (Ilist<t> returned for the GetAll method):

 PublicActionResult Index () {person P1=NewPerson () {Id =1, Name ="Liu Bei" }; Person P2=NewPerson () {Id =2, Name ="Guan Yu" }; Person P3=NewPerson () {Id =3, Name ="Zhang Fei" }; Person P4=NewPerson () {Id =4, Name ="Caocao" }; Person P5=NewPerson () {Id =5, Name ="Code Wei" }; Person P6=NewPerson () {Id =6, Name ="Guo Jia" }; List<Person> Listperson =NewList<person>() {P2,P3,P4,P5,P6}; using(Iredisclient rclient =PRCM. Getclient ()) {iredistypedclient<Person> Irperson = rclient.as<person>();                Irperson.deleteall (); //------------------------------------------Add--------------------------------------------//add A single piece of dataIrperson.store (p1); //add more than one piece of dataIrperson.storeall (Listperson); //------------------------------------------Query--------------------------------------------//LINQ SupportResponse.Write (Irperson.getall (). Where (m = m.id = =1). First (). Name);//Liu Bei//Note that the Iredistypedclient object Irperson Srore () is added in order to be read with the Irperson () methodResponse.Write (Irperson.getall (). First (m = M.id = =2). Name);//Guan Yu//------------------------------------------Delete--------------------------------------------Irperson.delete (p1); //Delete Liu BeiResponse.Write (Irperson.getall (). Count ());//5Irperson.deletebyid (2);//Delete Guan YuResponse.Write (Irperson.getall (). Count ());//4Irperson.deletebyids (Newlist<int> {3,4});//Delete Zhang Fei CaoResponse.Write (Irperson.getall (). Count ());//2Irperson.deleteall ();//Delete allResponse.Write (Irperson.getall (). Count ());//0            }            returnContent (""); }
View Code

In addition, because the interface does not implement the modified method, the modification has to pass the Iredisclient instance:

 PublicActionResult Index () {Pooledredisclientmanager PRCM=NewPooledredisclientmanager (Newlist<string> () {"127.0.0.1"},Newlist<string> () {"127.0.0.1"}, Redisconfig); Person P1=NewPerson () {Id =1, Name ="Liu Bei" }; Person P2=NewPerson () {Id =2, Name ="Guan Yu" }; Person P3=NewPerson () {Id =3, Name ="Zhang Fei" }; Person P4=NewPerson () {Id =4, Name ="Caocao" }; Person P5=NewPerson () {Id =5, Name ="Code Wei" }; Person P6=NewPerson () {Id =6, Name ="Guo Jia" }; List<Person> Listperson =NewList<person>() {P2,P3,P4,P5,P6}; using(Iredisclient rclient =PRCM. Getclient ()) {iredistypedclient<Person> Irperson = rclient.as<person>();                Irperson.storeall (Listperson); //Read all the keyslist<string> Listkeys =Irperson.getallkeys (); foreach(stringKeyinchListkeys) {Response.Write (Key+"<br/>"); }                //changes can only be modified by key//Urn:person:3//Urn:person:4//Urn:person:5//Ids:person//Urn:person:1//Urn:person:6//Urn:person:2Person P7 =NewPerson () {Id =8, Name ="Shake Sacred Cow" }; Rclient.set ("Urn:person:1", P7); Response.Write (Irperson.getall (). First (M= = M.id = =8). Name);//output Shake Sacred cow            }            returnContent (""); }
View Code

Servicestack.redis's iredistypedclient 04_ turn

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.