Redis Combat (vi)

Source: Internet
Author: User

Querying data

1. Using LINQ to match keyword queries

using(varRedisclient =redismanager.getclient ()) {                    varuser = Redisclient.gettypedclient<user>(); varuserlist = user. GetAll (). Where (x =x.job.position.contains (Txtscreenposition.text)).                    ToList (); if(Userlist.count >0)                    {                        varHtmlstr =string.                        Empty; foreach(varUinchuserlist) {Htmlstr+="<li>id="+ U.id +"&nbsp;&nbsp; Name:"+ U.name +"&nbsp;&nbsp; Department:"+ U.job.position +"</li>"; } Lblpeople.text=Htmlstr; } Lblshow.text="total after filtering:"+ userList.Count.ToString () +"people! "; }

2 , using key to query data

in Redis, you can query all the key,c# in the current database by entering the keys * to achieve the same effect with the following code.
                var user = Redisclient.gettypedclient<user>();                 var userkeylist = user. Getallkeys ();

We explain each of the following:

Seq:user: The ID self-increment sequence used to maintain the current type of User as the object's unique ID, which is why the getnextsequence () function is used to get the latest ID for the current database.
ids:user:
urn:user:1: This is the save

< Span style= "text-align:justify;" > Enter in Redis-client: Get urn:user:1 to get JSON type data.

We can easily query the value by key, the code is as follows

                using(varRedisclient =redismanager.getclient ()) {                    varKeyValue =string.                    Empty; Try                    {                        varuser = Redisclient.gettypedclient<user>(); varValue =user.                           GetValue (Txtkey.text); KeyValue+="id="+ value. Id +"&nbsp;&nbsp; Name:"+ value. Name +"&nbsp;&nbsp; Department:"+value.                    Job.position; }                    Catch(Exception ex) {KeyValue+=Ex.                    ToString (); } Lblpeople.text=Keyvalue.tojson (); Lblshow.text=string.                Empty; }

Redis Combat (vi)

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.