Home  >  Article  >  Database  >  How to use redis

How to use redis

藏色散人
藏色散人Original
2019-10-24 12:05:536204browse

How to use redis

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.

How to use redis

Create a new web project. The project structure diagram is as follows.

How to use redis

Set key-value pairs in the SpirngRedis file and obtain the corresponding values ​​of the keys. See the code below.

How to use redis

Save the User object in the UserServiceTest file and query it after saving. The code is as shown in the figure below.

How to use redis

Set the redis cache and cache name in the spring-redis.xml file. The code is as shown below.

How to use redis

Introduce the spring-redis.xml and spring-datasource-bonecp.xml files into the beans.xml file respectively. The code is shown below.

How to use redis

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.

How to use redis

Finally open it, the userservicetest file will run and the data will be retrieved directly from the cache, as shown in the figure below.

How to use redis

The above is the detailed content of How to use redis. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn