订阅
package jsyf.com.redis.cluster; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import redis.clients.jedis.JedisCluster; import redis.clients.jedis.JedisPubSub; import javax.annotation.PostConstruct; @Component public class Subscription { @Autowired private JedisCluster jedisCluster; @PostConstruct public void startSub() { new Thread(() -> { jedisCluster.subscribe(new JedisPubSub() { @Override public void onMessage(String channel, String message) { System.out.println("onMessagex:" + message); } }, "WEIXIN"); }).start(); } }
发布
@Autowired private JedisCluster jedisCluster; public JSonObject sendMsgToUser(String jsonData) throws Exception { Long count = jedisCluster.publish("WEIXIN", "您有一条微信技术文章."); System.out.println("count = " + count); return new JSONObject(); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)