How to use redis?
After installing redis, enter "redis-cli" on the command line and press Enter and enter "auth passowod" to confirm whether redis is installed.
Create a new web project. The project structure diagram is as follows.
Set key-value pairs in the SpirngRedis file and obtain the corresponding values of the keys. See the code below.
Save the User object in the UserServiceTest file and query it after saving. The code is as shown in the figure below.
Set the redis cache and cache name in the spring-redis.xml file. The code is as shown below.
Introduce the spring-redis.xml and spring-datasource-bonecp.xml files into the beans.xml file respectively. The code is shown below.
Use spring annotations in the userservice file to cache the data saved in userservicetest. The name is the same as that saved in the spring-redis.xml file, as pointed by the red arrow in the figure below.
Finally open it, the userservicetest file will run and the data will be retrieved directly from the cache, as shown in the figure below.
The above is the detailed content of How to use redis. For more information, please follow other related articles on the PHP Chinese website!