This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13932|Reply: 0

[Source] Java Redis - Implements simple conditional queries

[Copy link]
Posted on 3/5/2019 4:36:03 PM | | | |
First, import the jar package



Second, realize simple conditional query

Create a User entity class


Create 5 objects and put them in the cache so we can test them

When queried in redis, you can see that 5 user objects have been stored in the cache



Next, first implement a single-condition query, such as querying a user with an age of 15 and a user with a gender of m
Since Redis is nosql and cannot directly use where to query conditions like mysql, Redis can only use a stupid method to implement conditional query: save all qualified users in a set




So, if you want to query the user with an age of 15, you need to first remove all the UUIDs from the USER_TABLE_AGE_15, and then remove the user from the USER_TABLE

The results are as follows:

User [id=63a970ec-e997-43e0-8ed9-14c5eb87de8b, name=y1, sex=m, age=15]
User [id=aa074a2a-88d9-4b50-a99f-1375539164f7, name=y4, sex=n, age=15]
So if you need a user with an age of 15 and a gender of M, it's very simple, get it
USER_TABLE_AGE_15 and USER_TABLE_SEX_m, and then obtain them from the USER_TABLE.


User [id=63a970ec-e997-43e0-8ed9-14c5eb87de8b, name=y1, sex=m, age=15]






Previous:Huawei Engineer Exam Study Materials
Next:
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com