Springboot整合redission
...小于 1 分钟
Springboot整合redission
Spring Boot整合Redisson和Redis的主要区别在于Redisson提供了更高级的功能和抽象,它不仅包含了Redis的基本操作,还提供了分布式锁、分布式集合、可扩展的事件发布/订阅模式等。
pom.xml依赖引入
<!-- 引入redission -->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.16.2</version>
</dependency>
RedisController测试
@Controller
public class RedisController {
@Autowired
private RedissonClient redissonClient;
@RequestMapping("/publish")
@ResponseBody
public String publishMessage() {
System.out.println("..........publish..........");
RTopic topic = redissonClient.getTopic("myTopic");
topic.publish("Hello, Redisson!");
return "success";
}
@RequestMapping("/subscribe")
@ResponseBody
public String subscribeMessage() {
System.out.println("..........subscribe..........");
RTopic topic = redissonClient.getTopic("myTopic");
topic.addListener(String.class, (message, channel) -> {
System.out.println("now Received message: " + message);
});
return "success";
}
}
Powered by Waline v3.1.3