package com.jxy.order.vo;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;

/**
 * @Description TODO
 * @Date 2023/5/29 15:24
 * @Author 杜懿
 */
public class TestJdis {

    public static void main(String[] args) {
        Jedis jr = null;
        try {
            jr = new Jedis("10.168.2.197", 6379, 0);
            //jr = new Jedis("10.168.2.125", 6379, 0);
            jr.auth("");

            // jr客户端配置监听两个channel
            jr.subscribe(new JedisPubSub() {
                @Override
                public void onMessage(String channel, String message) {
                    super.onMessage(channel, message);
                    System.out.println("订阅主题："+channel+",收到消息"+message);
                }

                @Override
                public int getSubscribedChannels() {
                    return super.getSubscribedChannels();
                }
            }, "kline");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (jr != null) {
                jr.disconnect();
            }
        }
    }

}
