消息通知
使用Redis实现任务队列
使用列表, lpush 和 rpop 命令实现队列的概念

添加数据

public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 1000; i++) {
            jedis.lpush("num", String.valueOf(i));
            Thread.currentThread().sleep(2000);
        }
    }

消费

 public static void main(String[] args) throws InterruptedException {
        while (true) {
            String rpop = jedis.rpop("num");
            System.out.println(rpop);
            Thread.currentThread().sleep(3000);
        }
    }

 

 


发布/订阅 模式(publish/subscribe)
此模式有两种角色,分别是发布者和订阅者,订阅者可以定阅一个或多个频道(channel)

发布者发布消息,返回接受到这条信息的订阅者数量
publish channel message

定阅频道
subscribe channel [channel ...]

取消定阅
unsubscribe channel [channel ...]

 

相关文章:

  • 2022-01-06
  • 2021-10-04
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-14
  • 2021-07-10
  • 2021-12-18
  • 2021-08-19
  • 2022-12-23
  • 2022-02-14
  • 2021-06-12
相关资源
相似解决方案