http://www.cnblogs.com/mushroom/p/4470006.html#one
package com.demo.redis;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import org.apache.commons.lang3.StringUtils;
import com.support.RedisTool;
import redis.clients.jedis.JedisPubSub;
public class Test {
public static void main(String[] args) {
new Test().test();
}
public void test1() {
String loginip = "127.0.0.1";
long timestamp = System.currentTimeMillis() / 1000;
Integer logType = 2;
List<?> event = Arrays.asList("userId", loginip, timestamp, logType);
System.err.println(event);
}
static String topic = "test";
public void test() {
JedisPubSubListener listener = new JedisPubSubListener();
Thread th = new Thread(new Receive(topic, listener));
th.setName("abc");
th.start();
input();
}
public void input() {
Scanner scanner = new Scanner(System.in);
while (true) {
String str = scanner.nextLine();
if (StringUtils.equals(str, "quit")) {
break;
}
RedisTool.keep().getJedis().publish(topic, str);
}
scanner.close();
RedisTool.keep().getJedis().shutdown();
}
}
class Receive implements Runnable {
String topic;
JedisPubSubListener listener;
public Receive() {
}
public Receive(String topic, JedisPubSubListener listener) {
this.topic = topic;
this.listener = listener;
}
@Override
public void run() {
RedisTool.keep().getJedis().subscribe(listener, topic);
}
}
class JedisPubSubListener extends JedisPubSub {
@Override
public void onMessage(String channel, String message) {
String name = Thread.currentThread().getName();
System.err.println(name + ": " + message);
}
}
分享到:
相关推荐
Redis发布与订阅系统源码,统一配置更新数据库,亲测可用,简单易懂。切记运行程序前要开启Redis服务.
Redis支持跨进程发布订阅机制。代码实现了key过期的notification.
Java实现Redis的消息订阅和发布实例。
实现redis发布订阅的一个小Demo,一个发布消息,其他订阅了的都能接收消息
Redis 发布订阅 Demo,SpringBoot 使用 Redis 发布订阅模式
基于muduo网络库的集群聊天服务器和客户端源码,使用nginx tcp负载均衡,mysql数据库,redis发布-订阅数据库,redis发布-订阅 基于muduo网络库的集群聊天服务器和客户端源码,使用nginx tcp负载均衡,mysql数据库,...
基于netcore 3.0的redis发布订阅示例代码,直接可以运行,学习netcore和redis的很好入门示例代码。
本案例包含redis的发布订阅功能,以及dotnet core+SignalR实现的简单即时通信,并提供文档笔记。本案例初衷是想结合redis的发布订阅功能+websocket实现消息客户端页面订阅指定的消息,并在客户端页面进行显示;
Redis支持跨进程发布订阅机制。代码实现了key过期的notification.
redispubandsub订阅预发布,本包使用C#编写的代码,在使用之前需要有redis的服务,否则无法使用
redis绑定webSocket发布订阅,进行长连接推送,用以暂时进度条,查看任务进行状态,失败数量与成功数量
redis订阅机制,一方面推送消息,另一方面同时接收消息。
Redis在Delphi7下使用,支持发布、订阅等
SpringBoot + Redis实现事件的发布订阅功能。详情可看博文https://blog.csdn.net/linhaiyun_ytdx/article/details/103569370
springboot+redis+websocket 使用redis发布订阅实现websocket集群
redis消息订阅发布
可以工作在nginx tcp负载均衡环境中的集群聊天服务器和客户端源码 基于nuduo库实现 使用了redis发布订阅消息队列 数据库采用MySQL 可以工作在nginx tcp负载均衡环境中的集群聊天服务器和客户端源码 基于nuduo库实现 ...
redis开启服务后,用付服务端发送订阅,客户端将实时收到数据。
Redis中使用Java代码的方式实现发布订阅流程-发布者示例代码.zip
Java实现Redis的消息订阅和发布源码