redis use some kind of scene

Task background is this:
All of our databases are others defined, we can not change, then the database does not userName this field is that all of the user's name is not stored in the database. But back to the front but also the back-end them. We call external interface users can get all the names, but not all of the front-end user's name, according to the conditions you want to find. So I put all the user names and id cards linked together in order to improve efficiency, not every call interface, is stored redis.
Here Insert Picture Description
Before this code is called the external interface, you can get a json string containing the user information.
Some get the desired information through the json structure, then through getString () This method, values corresponding to the key value to get value.
The method can be stored directly redisTemplate map, as above: redisTemplate.opsForHash (), or will first oh ~ check out two key value data in accordance with the data before deleting the stored key value. Throws.
I'm here because check out feedId and name will be used, will be based on one to find another. So I put both separately and as a key value store twice. In this way one can go to get the other.
Here Insert Picture Description
Above: This is a place where used, taken from the redis out, it is the front end of a fuzzy query, to find possible according to the user's name, but the user's name did not even exist in the database. I can only find the corresponding feedId from redis by user name, and then go through the database feedId.
Here Insert Picture Description
Above: This is another place that is known feedId, but to display the name, you need to remove the name from redis by feedId.

. redisTemplate.opsForHash () get (1,2) ; a first key value is redis value, the second value is the key value in the map.
This fuzzy inquiry to investigate only through full name, otherwise you have to traverse the string, the name of every word are kept reids, this is actually simple, is not the same surname, or to throw an exception, and this unrealistic, so just do this function.

Released eight original articles · won praise 0 · Views 70

Guess you like

Origin blog.csdn.net/qq_41782623/article/details/104069919