These days just the new project used Redis, search the Internet, summed up
There are two kinds of online, one is to use the class to configure the management Redis, and the other is to write in Yaml or properties
I feel the way to unload Yaml is more intuitive, simple, below to briefly introduce, quite simple
1. Our project uses springboot2.0, and then we introduce redis dependencies into the POM in the following format
< Dependency > < groupId >org.springframework.boot</groupId> < Artifactid>spring-boot-starter-data-redis</artifactid> </dependency>
2. Inject in your class
@Autowired private Stringredistemplate stringredistemplate;
Or
@Autowired private Redistemplate redistemplate;
Then save the key, take the key, set the timeout time, and so on, other types of use Baidu on the line, a lot.
Use: Redistemplate.opsforvalue (). Set ("Name", "Tom"); Result: Redistemplate.opsforvalue (). Get ("name") output is Tom
Oh, yes, add a basic configuration file to the properties
# Redis Database index (default is 0) spring.redis.database=0# Redis server address spring.redis.host=127.0.0.1# Redis Server connection Port spring.redis.port= 6379# Redis Server connection password (default is empty) spring.redis.password=# connection pool Maximum number of connections (using negative values means there is no limit) spring.redis.pool.max-active=8# Connection pool Maximum blocking wait time (with negative values for no limit) spring.redis.pool.max-wait=-1# maximum idle connections in the connection pool spring.redis.pool.max-idle=8# Minimum idle connection in connection pool spring.redis.pool.min-idle=0# connection time-out (ms) spring.redis.timeout=5000
And then there's the search for all the approximate keys.
Stringredistemplate.keys ("xxx")
This usage must not be used in a production environment unless the amount of data is small ...
Springboot Integrated Redis