Example usage for org.springframework.data.redis.connection RedisConnection pSubscribe

List of usage examples for org.springframework.data.redis.connection RedisConnection pSubscribe

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection RedisConnection pSubscribe.

Prototype

void pSubscribe(MessageListener listener, byte[]... patterns);

Source Link

Document

Subscribes the connection to all channels matching the given patterns.

Usage

From source file:com.zxy.commons.cache.RedisUtils.java

/**
 * Subscribes the connection to all channels matching the given patterns. Once subscribed, a connection enters
 * listening mode and can only subscribe to other channels or unsubscribe. No other commands are accepted until the
 * connection is unsubscribed./*  w  w w .  j av  a2 s .co  m*/
 * <p>
 * Note that this operation is blocking and the current thread starts waiting for new messages immediately.
 * 
 * @param listener message listener
 * @param patterns channel name patterns
 */
public static void pSubscribe(MessageListener listener, byte[]... patterns) {
    redisTemplate.execute(new RedisCallback<Void>() {
        @Override
        public Void doInRedis(RedisConnection redis) throws DataAccessException {
            redis.pSubscribe(listener, patterns);
            return null;
        }
    });
}

From source file:com.zxy.commons.cache.RedisHelper.java

/**
 * Subscribes the connection to all channels matching the given patterns. Once subscribed, a connection enters
 * listening mode and can only subscribe to other channels or unsubscribe. No other commands are accepted until the
 * connection is unsubscribed.//from  w ww.java  2  s  .  co  m
 * <p>
 * Note that this operation is blocking and the current thread starts waiting for new messages immediately.
 * 
 * @param listener message listener
 * @param patterns channel name patterns
 */
public void pSubscribe(MessageListener listener, byte[]... patterns) {
    redisTemplate.execute(new RedisCallback<Void>() {
        @Override
        public Void doInRedis(RedisConnection redis) throws DataAccessException {
            redis.pSubscribe(listener, patterns);
            return null;
        }
    });
}