Servicestack.redis's iredistypedclient< Fourth >

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):

        Public ActionResult Index () {person P1 = new person () {Id = 1, Name = "Liu Bei"};            person P2 = new Person () {Id = 2, Name = "Guan Yu"};            Person P3 = new person () {Id = 3, Name = "Zhang Fei"};            person P4 = new Person () {Id = 4, Name = "Caocao"};            Person P5 = new person () {Id = 5, Name = "Code Wei"};            Person P6 = new Person () {Id = 6, Name = "Guo Jia"};            list<person> Listperson = new list<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 data                Irperson.store (p1);                Add more than one data Irperson.storeall (Listperson); ------------------------------------------Query----------The----------------------------------//linq supports Response.Write (Irperson.getall (). Where (m = m.id = = 1). First ().       Name); Liu Bei//Note that Srore () added with Iredistypedclient object Irperson can read Response.Write (Irperson) using the Irperson () method. GetAll (). First (m = M.id = = 2).       Name); Guan Yu//------------------------------------------Delete--------------------------------------------IRP Erson.    Delete (p1); Delete Liu Bei Response.Write (Irperson.getall ().      Count ()); 5 Irperson.deletebyid (2); Delete Guan Yu Response.Write (Irperson.getall ().      Count ());    4 Irperson.deletebyids (new list<int> {3,4}); Remove Zhang Fei Cao Response.Write (Irperson.getall ().      Count ());   2 Irperson.deleteall (); Delete all Response.Write (Irperson.getall ().      Count ());        0} return Content (""); }

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

        Public ActionResult Index () {Pooledredisclientmanager PRCM = new Pooledredisclientmanager (New L            Ist<string> () {"127.0.0.1"}, new List<string> () {"127.0.0.1"}, Redisconfig);            person P1 = new person () {Id = 1, Name = "Liu Bei"};            person P2 = new Person () {Id = 2, Name = "Guan Yu"};            Person P3 = new person () {Id = 3, Name = "Zhang Fei"};            person P4 = new Person () {Id = 4, Name = "Caocao"};            Person P5 = new person () {Id = 5, Name = "Code Wei"};            Person P6 = new Person () {Id = 6, Name = "Guo Jia"};            list<person> Listperson = new list<person> () {P2,P3,P4,P5,P6}; using (iredisclient rclient = prcm.                Getclient ()) {iredistypedclient<person> Irperson = rclient.as<person> ();                Irperson.storeall (Listperson);                      Read all key list<string> Listkeys = Irperson.getallkeys (); foreach (string key in Listkeys) {Response.Write (key + "<br/>");                 }//modified 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:2                Person P7 = new Person () {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} return Content (""); }

Servicestack.redis of iredistypedclient< fourth;

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.