當前位置: 首頁>>代碼示例>>Java>>正文


Java Jedis.subscribe方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Jedis.subscribe方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.subscribe方法的具體用法?Java Jedis.subscribe怎麽用?Java Jedis.subscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Jedis的用法示例。


在下文中一共展示了Jedis.subscribe方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: MessageConsumerRedisImpl

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 *
 * @param redisConnection redis 連接類
 * @param channels 訂閱的頻道列表
 */
public MessageConsumerRedisImpl(RedisConnection redisConnection, String[] channels) {
    Jedis jedis = null;
    try {
        if (channels != null && channels.length > 0) {
            jedis = redisConnection.getJedis();
            jedis.subscribe(new JedisPubSub() {
                @Override
                public void onMessage(String channel, String message) {
                    System.out.println("receive " + message + " from " + channel);
                    handleMessage(message);
                }
            }, channels);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
}
 
開發者ID:gaochao2000,項目名稱:redis_util,代碼行數:27,代碼來源:MessageConsumerRedisImpl.java

示例2: subscribe

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public void subscribe(JedisPubSub jedisPubSub, String channel) {
    Collection<JedisPool> poolCollection = jedisCluster.getClusterNodes().values();
    Iterator iterator = poolCollection.iterator();

    while(iterator.hasNext()) {
        JedisPool jedisPool = (JedisPool)iterator.next();
        Jedis jedis = null;

        try {
            jedis = jedisPool.getResource();
            jedis.subscribe(jedisPubSub, new String[]{channel});
        } catch (Exception var11) {
            throw new RuntimeException(var11);
        } finally {
            jedisPool.returnResourceObject(jedis);
        }
    }

}
 
開發者ID:bitstd,項目名稱:bitstd,代碼行數:20,代碼來源:RedisCacheWithCluster.java

示例3: subscribe

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public void subscribe(JedisPubSub jedisPubSub, String channel) {
    Jedis jedis = null;

    try {
        jedis = pool.getResource();
        jedis.subscribe(jedisPubSub, new String[]{channel});
    } catch (Exception var8) {
        throw new RuntimeException(var8);
    } finally {
        pool.returnResourceObject(jedis);
    }

}
 
開發者ID:bitstd,項目名稱:bitstd,代碼行數:14,代碼來源:RedisCacheWithoutCluster.java

示例4: run

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public void run() {
    running.set(true);
    while (running.get()) {
        j = new Jedis(host, port);
        try {
            // double check that it is not being shutdown
            if (!running.get()) {
                break;
            }
            j.subscribe(new JedisPubSub() {
                @Override
                public void onMessage(String channel, String message) {
                    log.fine("Sentinel " + host + ":" + port + " published: " + message + ".");

                    String[] switchMasterMsg = message.split(" ");

                    if (switchMasterMsg.length > 3) {

                        if (masterName.equals(switchMasterMsg[0])) {
                            initPool(toHostAndPort(Arrays.asList(switchMasterMsg[3], switchMasterMsg[4])));
                        } else {
                            log.fine("Ignoring message on +switch-master for master name "
                                    + switchMasterMsg[0] + ", our master name is " + masterName);
                        }

                    } else {
                        log.severe("Invalid message received on Sentinel " + host + ":" + port
                                + " on channel +switch-master: " + message);
                    }
                }
            }, "+switch-master");

        } catch (JedisConnectionException e) {
            if (running.get()) {
                log.log(Level.SEVERE, "Lost connection to Sentinel at " + host + ":" + port
                        + ". Sleeping 5000ms and retrying.", e);
                try {
                    Thread.sleep(subscribeRetryWaitTimeMillis);
                } catch (InterruptedException e1) {
                    log.log(Level.SEVERE, "Sleep interrupted: ", e1);
                }
            } else {
                log.fine("Unsubscribing from Sentinel at " + host + ":" + port);
            }
        } finally {
            j.close();
        }
    }
}
 
開發者ID:YanXs,項目名稱:nighthawk,代碼行數:50,代碼來源:JaRedisSentinelPool.java


注:本文中的redis.clients.jedis.Jedis.subscribe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。