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 +" Name:"+ U.name +" 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 +" Name:"+ value. Name +" Department:"+value. Job.position; } Catch(Exception ex) {KeyValue+=Ex. ToString (); } Lblpeople.text=Keyvalue.tojson (); Lblshow.text=string. Empty; }
Redis Combat (vi)