疯狂的狮子li
2021-11-18 f8487f581be226c3def30676055e0e32a5ac341a
ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisPubSubController.java
@@ -4,6 +4,7 @@
import com.ruoyi.common.utils.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -23,7 +24,7 @@
   @ApiOperation("发布消息")
   @GetMapping("/pub")
   public AjaxResult<Void> pub(String key, String value){
    public AjaxResult<Void> pub(@ApiParam("通道Key") String key, @ApiParam("发送内容") String value) {
      RedisUtils.publish(key, value, consumer -> {
         System.out.println("发布通道 => " + key + ", 发送值 => " + value);
      });
@@ -32,7 +33,7 @@
   @ApiOperation("订阅消息")
   @GetMapping("/sub")
   public AjaxResult<Void> sub(String key){
    public AjaxResult<Void> sub(@ApiParam("通道Key") String key) {
      RedisUtils.subscribe(key, String.class, msg -> {
         System.out.println("订阅通道 => " + key + ", 接收值 => " + msg);
      });