1、发布/订阅
Redis的发布与订阅功能可以让客户端通过广播方式,将 消息(message)同时发送给可能存在的多个客户端,并且发送消息的客户端不需要知道接收消息的客户端的具体信息。在Redis中,客户端可以通过订阅特定的 频道(channel)来接收发送至该频道的消息,我们把这些订阅频道的客户端称为订阅者(subscriber)。客户端还可以通过向频道发送消息的方式,将消息发送给频道的所有订阅者,我们把这些发送消息的客户端称为发送者(publisher)。
2、springboot整合
引入pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
RedisConfig配置类
package com.ex