Package com.cxy.redisclient

Source Code of com.cxy.redisclient.PubSub

package com.cxy.redisclient;

import redis.clients.jedis.JedisPubSub;

import com.cxy.redisclient.service.PubSubService;

import junit.framework.TestCase;

public class PubSub extends TestCase {
  public void testPub(){
    PubSubService service = new PubSubService();
    service.publish(13, "test", "16:16 message");
  }
  public void testSub(){
    PubSubService service = new PubSubService();
    service.subscribe(13, new JedisPubSub() {

      @Override
      public void onMessage(String channel, String message) {
        System.out.println(channel + " received:" + message);
       
      }

      @Override
      public void onPMessage(String pattern, String channel,
          String message) {
        System.out.println(pattern + " received:" + message);
       
      }

      @Override
      public void onSubscribe(String channel, int subscribedChannels) {
        System.out.println(channel + " subscribed");
      }

      @Override
      public void onUnsubscribe(String channel, int subscribedChannels) {
        // TODO Auto-generated method stub
       
      }

      @Override
      public void onPUnsubscribe(String pattern, int subscribedChannels) {
        // TODO Auto-generated method stub
       
      }

      @Override
      public void onPSubscribe(String pattern, int subscribedChannels) {
        System.out.println(pattern + " subscribed");
       
      }
     
    }, "test.*");
  }
}
 
TOP

Related Classes of com.cxy.redisclient.PubSub

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.