1 前提准备

  1.1 创建一个springboot项目

    技巧01:本博文基于springboot2.0创建

  1.2 安装redis

    1.2.1 linux版本

      参考博文

    1.2.2 windows版本

      到redis官网下载windows版本的压缩包后,解压即可

  1.3 redis使用

    本博文以window版本为例子,linux版本请参见

    1.3.1 开启服务端

      》进入到解压后的redis根目录

Springboot21 整合redis、利用redis实现消息队列

        》执行 redis-server.exe

Springboot21 整合redis、利用redis实现消息队列

    1.3.2 开启客户端

      进入到redis解压目录 -> 执行 redis-cli.exe

Springboot21 整合redis、利用redis实现消息队列

    1.3.3 测试redis服务端和客户端的通信

       在redis客户端执行 ping,如果返回了 PONG 就表明redis前后端通信正常

Springboot21 整合redis、利用redis实现消息队列

    1.3.4 关闭

      客户端和服务端都用 Ctrl + C 就可以关闭了

 

2 SpringBoot 集成 Redis

  2.1 创建一个SpringBoot项目

    技巧01:创建时引入 spring-boot-starter-web 和 spring-boot-starter-data-redis

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cn.xiangxu</groupId>
    <artifactId>redis_pub_sub</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>redis_pub_sub</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>org.springframework.boot</groupId>-->
            <!--<artifactId>spring-boot-starter-data-redis-reactive</artifactId>-->
        <!--</dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.0</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>
pom.xml

相关文章: