C # Redis Combat (vi)

Source: Internet
Author: User

Vi. Querying dataIn C # Redis Combat (V) describes how to delete data in Redis, this article will continue to describe the query in Redis.
1. Using LINQ to match keyword queries [CSharp]View Plain copy
  1. using (var redisclient = redismanager.getclient ())
  2. {
  3. var user = redisclient.gettypedclient<user> ();
  4. var userlist = user. GetAll (). Where (x = X.job.position.contains (Txtscreenposition.text)). ToList ();
  5. if (Userlist.count > 0)
  6. {
  7. var htmlstr = string.  Empty;
  8. foreach (Var u in userlist)
  9. {
  10. Htmlstr + = "<li>id=" + u.id + "Name:" + u.name + "department:" + u.job.position + "</li>";
  11. }
  12. Lblpeople.text = Htmlstr;
  13. }
  14. Lblshow.text = "Filter after total:" + userList.Count.ToString () + "People!"  ";
  15. }

The code above implements the function of matching the department to query the data, enter. NET, and filter out one of the Java departments. The query results are as follows:
2 , through 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. [CSharp]View Plain copy
    1. var user = redisclient.gettypedclient<user> ();
    2. var userkeylist = user. Getallkeys ();

all keys are saved in the Userkeylist code .
careful readers will find that the number of keys queried here differs from the amount of data stored in the database
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: A list of all object IDs in the same type of user, equivalent to an index that contains all the IDs of the same type user;
urn:user:1: This is the save Enter in Redis-client: Get urn:user:1 to get JSON type data.

with the above instructions, we can easily query the value by key, the code is as follows: [CSharp]View Plain copy
  1. using (var redisclient = redismanager.getclient ())
  2. {
  3. var keyValue = string.  Empty;
  4. Try
  5. {
  6. var user = redisclient.gettypedclient<user> ();
  7. var value = user. GetValue (Txtkey.text);
  8. KeyValue + = "id=" + value. Id + "Name:" + value. Name + "department:" + value.  Job.position;
  9. }
  10. catch (Exception ex)
  11. {
  12. KeyValue + = ex. ToString ();
  13. }
  14. Lblpeople.text = Keyvalue.tojson ();
  15. Lblshow.text = string.  Empty;
  16. }
The effect is as follows:

C # 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.