Java Code Examples for redis.clients.jedis.Jedis#psubscribe()

The following examples show how to use redis.clients.jedis.Jedis#psubscribe() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JRedisCache.java    From springJredisCache with Apache License 2.0 6 votes vote down vote up
/**
 * 通常为了适应大多数场景  还是使用这方式订阅吧
 * <p/>
 * 表达式的方式订阅
 * 使用模式匹配的方式设置要订阅的消息            订阅得到信息在JedisPubSub的onMessage(...)方法中进行处理
 *
 * @param patterns
 */
@Override
public void psubscribe(final String... patterns) {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        final byte[][] ps = new byte[patterns.length][];
        for (int i = 0; i < ps.length; i++) {
            ps[i] = SafeEncoder.encode(patterns[i]);
        }
        jedis.psubscribe(jRedisBinaryPubSub, ps);
    } catch (Exception ex) {
        coverException(ex, jedisPool, jedis);
    } finally {
        if (jedis != null && jedis.isConnected()) {
            jedisPool.returnResource(jedis);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("close redis connection-{" + jedis.toString() + "}");
            }
        }
    }
}
 
Example 2
Source File: JedisUtil.java    From scaffold-cloud with MIT License 5 votes vote down vote up
/**
 * 调用jedis的psubscribe()方法
 *
 * @param jedisPubSub
 * @param patterns
 */
public static void psubscribe(JedisPubSub jedisPubSub, String... patterns) {
    Jedis jedis = null;
    try {
        jedis = getResource();
        jedis.psubscribe(jedisPubSub, patterns);
    } catch (Exception e) {
        logger.warn("psubscribe patterns==> {} exception==> {}", patterns, e);
    } finally {
        close(jedis);
    }
}
 
Example 3
Source File: AidrFetcherJsonInputProcessor.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
public void run() {
	//this.setMaxLogWritesPerMinute(2);

	while (true) {
		if (Thread.interrupted())
			return;

		Jedis redis = null;

		try {
			redis = DataStore.getJedisConnection();

			Subscriber subscriber = new Subscriber(outputQueueName);
			redis.psubscribe(subscriber, inputQueueName);
			redisLoadShedder
					.put(inputQueueName,
							new LoadShedder(
									Integer.parseInt(TaggerConfigurator
											.getInstance()
											.getProperty(
													TaggerConfigurationProperty.PERSISTER_LOAD_LIMIT)),
									Integer.parseInt(TaggerConfigurator
											.getInstance()
											.getProperty(
													TaggerConfigurationProperty.PERSISTER_LOAD_CHECK_INTERVAL_MINUTES)),
									true,inputQueueName));
Thread.sleep(60000);
		} catch (Exception e) {
			logger.error("RedisInputProcessor", e);
		} finally {
			DataStore.close(redis);
		}
	}
}