本文整理汇总了Java中redis.clients.jedis.BinaryJedisPubSub类的典型用法代码示例。如果您正苦于以下问题:Java BinaryJedisPubSub类的具体用法?Java BinaryJedisPubSub怎么用?Java BinaryJedisPubSub使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryJedisPubSub类属于redis.clients.jedis包,在下文中一共展示了BinaryJedisPubSub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RedisPubSubSync
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
public RedisPubSubSync(final CacheTemplate cacheTemplate) {
this.cacheTemplate = cacheTemplate;
this.cacheSyncHandler = new CacheSyncHandler(this.cacheTemplate);
this.jedisTemplate = cacheTemplate.getJedisTemplate();
new Thread(new Runnable() {
@Override
public void run() {
jedisTemplate.subscribe(new BinaryJedisPubSub() {
@Override
public void onMessage(byte[] channel, byte[] message) {
Command cmd = jedisTemplate.deserializeVal(message);
if (cmd != null) {
if ((cmd.src != null && !cmd.src.equals(Cache.ID)) || cmd.oper == Command.OPT_FETCH) {
logger.debug("recieve from " + cmd.src + " > " + cmd.toString());
cacheSyncHandler.handle(cmd);
}
}
}
}, Cache.CACHE_STORE_SYNC);
}
}, "RedisPubSubSync.Subscribe").start();
}
示例2: JbootEhredisCacheImpl
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
public JbootEhredisCacheImpl() {
this.ehcacheImpl = new JbootEhcacheImpl();
this.ehcacheImpl.setCacheEventListener(this);
this.redisCacheImpl = new JbootRedisCacheImpl();
this.clientId = StringUtils.uuid();
this.serializer = Jboot.me().getSerializer();
this.redis = redisCacheImpl.getRedis();
this.redis.subscribe(new BinaryJedisPubSub() {
@Override
public void onMessage(byte[] channel, byte[] message) {
JbootEhredisCacheImpl.this.onMessage((String) serializer.deserialize(channel), serializer.deserialize(message));
}
}, serializer.serialize(channel));
}
示例3: createClosureExSet
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
@Override
protected ClosureExSet createClosureExSet(final Object event) {
ClosureExSet set = super.createClosureExSet(event);
new Thread(new Runnable() {
@Override
public void run() {
// 这里会阻塞
// TODO 是否需要把 BinaryJedisPubSub 缓存?做unsubscribe操作
jedisCluster.subscribe(new BinaryJedisPubSub() {
@Override
public void onMessage(byte[] channel, byte[] message) {
Object evt = deserialize(channel);
Object[] args = deserialize(message);
// 这里一定要call父类的方法
RedisEventBus.super.doFireEvent(evt, args);
}
}, serialize(event));
}
}, "RedisSubscriber" + threadIndex.incrementAndGet() + "-thread-").start();
return set;
}
示例4: subscribe
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
public void subscribe(final BinaryJedisPubSub jedisPubSub, final String... channels) {
if (cluster) {
jedisCluster.subscribe(jedisPubSub, convertObjectArrayToByteArray_serializeKey(channels));
} else {
jedisOperator.subscribe(jedisPubSub, convertObjectArrayToByteArray_serializeKey(channels));
}
}
示例5: subscribe
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
public void subscribe(final BinaryJedisPubSub jedisPubSub, final byte[]... channels) {
execute(new JedisExecutor<Void>() {
@Override
Void doInJedis(Jedis jedis) {
jedis.subscribe(jedisPubSub, channels);
return null;
}
});
}
示例6: JbootRedismqImpl
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
public JbootRedismqImpl() {
initChannels();
JbootmqRedisConfig redisConfig = Jboot.config(JbootmqRedisConfig.class);
if (redisConfig.isConfigOk()) {
redis = JbootRedisManager.me().getRedis(redisConfig);
} else {
redis = Jboot.me().getRedis();
}
if (redis == null) {
throw new JbootIllegalConfigException("can not use redis mq (redis mq is default), " +
"please config jboot.redis.host=yourhost and check your jboot.properties, " +
"or use other mq component. ");
}
Object[] channels = this.channels.toArray();
redis.subscribe(new BinaryJedisPubSub() {
@Override
public void onMessage(byte[] channel, byte[] message) {
notifyListeners(redis.bytesToKey(channel), Jboot.me().getSerializer().deserialize(message));
}
}, redis.keysToBytesArray(channels));
dequeueThread = new Thread(this);
dequeueThread.start();
}
示例7: subscribe
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
@Override
public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) {
Span span = helper.buildSpan("subscribe");
span.setTag("channels", Arrays.toString(channels));
try {
super.subscribe(jedisPubSub, channels);
} catch (Exception e) {
onError(e, span);
throw e;
} finally {
span.finish();
}
}
示例8: psubscribe
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
@Override
public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) {
Span span = helper.buildSpan("psubscribe");
span.setTag("patterns", Arrays.toString(patterns));
try {
super.psubscribe(jedisPubSub, patterns);
} catch (Exception e) {
onError(e, span);
throw e;
} finally {
span.finish();
}
}
示例9: testPsubscribe
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
@Test
public void testPsubscribe() {
BinaryJedisPubSub listener = mock(BinaryJedisPubSub.class);
RedisFacade.RedisPubSub facadeListener = mock(RedisFacade.RedisPubSub.class);
when(facadeListener.getLinked()).thenReturn(listener);
String pattern = "test";
rf.psubscribe(facadeListener, pattern);
ArgumentCaptor<BinaryJedisPubSub> capture = ArgumentCaptor.forClass(BinaryJedisPubSub.class);
verify(facadeListener).link(capture.capture());
verify(jedis).psubscribe(capture.getValue(), SafeEncoder.encode(pattern));
}
示例10: testPsubscribe
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
@Test
public void testPsubscribe() {
BinaryJedisPubSub listener = mock(BinaryJedisPubSub.class);
RedisFacade.RedisPubSub facadeListener = mock(RedisFacade.RedisPubSub.class);
when(facadeListener.getLinked()).thenReturn(listener);
String pattern = "test";
rf.psubscribe(facadeListener, pattern);
ArgumentCaptor<BinaryJedisPubSub> capture = ArgumentCaptor.forClass(BinaryJedisPubSub.class);
verify(facadeListener).link(capture.capture());
verify(jedisCluster).psubscribe(capture.getValue(), SafeEncoder.encode(pattern));
}
示例11: subscribe
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
@Override
public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) {
redis.clients.jedis.Jedis delegate = pool.getResource();
try {
delegate.subscribe(jedisPubSub, channels);
} finally {
pool.returnResource(delegate);
}
}
示例12: psubscribe
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
@Override
public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) {
redis.clients.jedis.Jedis delegate = pool.getResource();
try {
delegate.psubscribe(jedisPubSub, patterns);
} finally {
pool.returnResource(delegate);
}
}
示例13: punsubscribe
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
@Override
public void punsubscribe(final RedisPubSub listener, byte[] pattern) {
((BinaryJedisPubSub) listener.getLinked()).punsubscribe(pattern);
}
示例14: psubscribe
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
@Override
public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) {
}
示例15: createResultListener
import redis.clients.jedis.BinaryJedisPubSub; //导入依赖的package包/类
private BinaryJedisPubSub createResultListener() {
JedisHelper.BinaryCallBackPubSub pubSub = new JedisHelper.BinaryCallBackPubSub();
pubSub.addOnMessageListener(this::onMessage);
return pubSub;
}