The use of Springboot integrated redis--redistemplate

Source: Internet
Author: User
Tags serialization

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.