I. Overview
For an overview of related Redis, see the NoSQL Chapter
Redistemplate's introduction, reference : http://blog.csdn.net/ruby_one/article/details/79141940
Stringredistemplate as a subclass of Redistemplate, only supports the operation of the KV string
The relationship between Stringredistemplate and Redistemplate is Stringredistemplate inheritance redistemplate. The data of the two is not common, that is to say Stringredistemplate can only manage the data inside the stringredistemplate,
Redistemplate can only manage data in the redistemplate. There are two types of serialization strategies used by the SDR, one is the serialization strategy of string and the other is the JDK's serialization strategy. The stringredistemplate default is a string serialization policy, and both the saved key and value are saved with this policy serialization. Redistemplate uses the JDK's serialization policy by default, and the saved key and value are saved with this policy serialization.
More, refer to Javadoc: Click to view
second, the introduction
1. Install the Windows version of Redis
Since Redis for Windows is only used for personal testing, it's easy to download the zip unzip version, and the related configuration items are not mentioned here, refer to the introduction of Redis under Linux
Click to download: https://github.com/MicrosoftArchive/redis/releases
unzip after downloading;
Use the following command to start the server in the directory where you unzipped: (Because of the Win10 PowerShell used here, you need to add./, or configure environment variables to avoid using.)
./redis-server.exe redis.windows.conf
This does not register it as a Windows service, closes the window, and then shuts down the Redis
Start the command side:
127.0. 0.1 6379
2. Introduction of dependency
<!--Springboot Integrated Redis - <Dependency> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-starter-data-redis</Artifactid> </Dependency>
Only this one Redis dependency can be introduced here, and the other 3 are automatically dependent:
3. Configuring Redis in Application.yml
# Redis Spring.redis.hostname=127.0. 0.1 Spring. redis.port=6379 spring. redis.pool.maxactive=8 Spring. redis.pool.maxwait=-1 spring. redis.pool.maxidle=8 Spring. redis.pool.minidle=0 spring. redis.timeout=0
Yml to Yml:
# Redis configuration, the default configuration is also available for Redis: host:127.0.0.1 port:6379 pool: max-active:8 max-wait : 1 max-idle:8 min-idle:0 timeout:0
There are many default configurations that can be used directly with the default
If you switch to cluster mode, the configuration changes are as follows:
Spring: application: name:spring-boot-redis redis: host:192.168.145.132 port:6379 timeout:20000 cluster: nodes:192.168.211.134:7000,192.168.211.134:7001,192.168.211.134:7002 maxredirects:6 Pool: max-active:8 min-idle:0 max-idle:8 max-wait: 1
Corresponding Configuration class: Org.springframework.boot.autoconfigure.data.redis.RedisProperties
4. Establishing a Redis configuration class
The use of Springboot integrated redis--redistemplate