当前位置: 首页>>代码示例>>Java>>正文


Java Jedis.publish方法代码示例

本文整理汇总了Java中redis.clients.jedis.Jedis.publish方法的典型用法代码示例。如果您正苦于以下问题:Java Jedis.publish方法的具体用法?Java Jedis.publish怎么用?Java Jedis.publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis.clients.jedis.Jedis的用法示例。


在下文中一共展示了Jedis.publish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: broadcastSanction

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public static void broadcastSanction(JsonCaseLine sanction, String toPseudo)
{
    new JsonModMessage("Samaritan", ModChannel.SANCTION, ChatColor.DARK_RED, "Joueur " + toPseudo + " banni pour le motif " + sanction.getMotif() + ". Durée : Définitif").send();

    Jedis jedis = API.getBungeeResource();
    jedis.publish("cheat", toPseudo + "#####" + sanction.getMotif());
    jedis.close();
}
 
开发者ID:SamaGames,项目名称:AntiCheat,代码行数:9,代码来源:ModerationTools.java

示例2: clean

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private void clean(Jedis jedis) {
    Set<String> keys = jedis.keys(root + Constants.ANY_VALUE);
    if (keys != null && keys.size() > 0) {
        for (String key : keys) {
            Map<String, String> values = jedis.hgetAll(key);
            if (values != null && values.size() > 0) {
                boolean delete = false;
                long now = System.currentTimeMillis();
                for (Map.Entry<String, String> entry : values.entrySet()) {
                    URL url = URL.valueOf(entry.getKey());
                    if (url.getParameter(Constants.DYNAMIC_KEY, true)) {
                        long expire = Long.parseLong(entry.getValue());
                        if (expire < now) {
                            jedis.hdel(key, entry.getKey());
                            delete = true;
                            if (logger.isWarnEnabled()) {
                                logger.warn("Delete expired key: " + key + " -> value: " + entry.getKey() + ", expire: " + new Date(expire) + ", now: " + new Date(now));
                            }
                        }
                    }
                }
                if (delete) {
                    jedis.publish(key, Constants.UNREGISTER);
                }
            }
        }
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:29,代码来源:RedisRegistry.java

示例3: publishOne

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private void publishOne(final String channel, final String message) {
  Thread t = new Thread(new Runnable() {
    public void run() {
      try {
        Jedis j = createJedis();
        j.publish(channel, message);
        j.disconnect();
      } catch (Exception ex) {
      }
    }
  });
  t.start();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:14,代码来源:PublishSubscribeCommandsTest.java

示例4: deferExpired

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private void deferExpired() {
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        try {
            Jedis jedis = jedisPool.getResource();
            try {
                for (URL url : new HashSet<URL>(getRegistered())) {
                    if (url.getParameter(Constants.DYNAMIC_KEY, true)) {
                        String key = toCategoryPath(url);
                        if (jedis.hset(key, url.toFullString(), String.valueOf(System.currentTimeMillis() + expirePeriod)) == 1) {
                            jedis.publish(key, Constants.REGISTER);
                        }
                    }
                }
                if (admin) {
                    clean(jedis);
                }
                if (! replicate) {
                	break;//  如果服务器端已同步数据,只需写入单台机器
                }
            } finally {
                jedisPool.returnResource(jedis);
            }
        } catch (Throwable t) {
            logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:29,代码来源:RedisRegistry.java

示例5: clean

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private void clean(Jedis jedis) {
    Set<String> keys = jedis.keys(root + Constants.ANY_VALUE);
    if (keys != null && keys.size() > 0) {
        for (String key : keys) {
            Map<String, String> values = jedis.hgetAll(key);
            if (values != null && values.size() > 0) {
                boolean delete = false;
                long now = System.currentTimeMillis();
                for (Map.Entry<String, String> entry : values.entrySet()) {
                    URL url = URL.valueOf(entry.getKey());
                    if (url.getParameter(Constants.DYNAMIC_KEY, true)) {
                        long expire = Long.parseLong(entry.getValue());
                        if (expire < now) {
                            jedis.hdel(key, entry.getKey());
                            delete = true;
                            if (logger.isWarnEnabled()) {
                                logger.warn("Delete expired key: " + key + " -> value: " + entry.getKey() + ", expire: " + new Date(expire) + ", now: " + new Date(now));
                            }
                        }
                        }
                }
                if (delete) {
                    jedis.publish(key, Constants.UNREGISTER);
                }
            }
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:29,代码来源:RedisRegistry.java

示例6: publish

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public void publish(byte[] channel, byte[] message) {
    Jedis jedis = null;

    try {
        jedis = pool.getResource();
        jedis.publish(channel, message);
    } catch (Exception var8) {
        throw new RuntimeException(var8);
    } finally {
        pool.returnResourceObject(jedis);
    }

}
 
开发者ID:bitstd,项目名称:bitstd,代码行数:14,代码来源:RedisCacheWithoutCluster.java

示例7: deferExpired

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private void deferExpired() {
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        boolean isBroken = false;
        try {
            Jedis jedis = jedisPool.getResource();
            try {
                for (URL url : new HashSet<URL>(getRegistered())) {
                    if (url.getParameter(Constants.DYNAMIC_KEY, true)) {
                        String key = toCategoryPath(url);
                        if (jedis.hset(key, url.toFullString(), String.valueOf(System.currentTimeMillis() + expirePeriod)) == 1) {
                            jedis.publish(key, Constants.REGISTER);
                        }
                    }
                }
                if (admin) {
                    clean(jedis);
                }
                if (!replicate) {
                    break;//  如果服务器端已同步数据,只需写入单台机器
                }
            } catch (JedisConnectionException e){
                isBroken = true;
            } finally {
                if(isBroken){
                    jedisPool.returnBrokenResource(jedis);
                } else {
                    jedisPool.returnResource(jedis);
                }
            }
        } catch (Throwable t) {
            logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
        }
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:36,代码来源:RedisRegistry.java

示例8: run

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public void run()
{
    Jedis jedis = SamaGamesAPI.get().getBungeeResource();

    if (jedis == null)
        return;

    try
    {
        JsonHub thisHub = new JsonHub();
        thisHub.setHubNumber(Integer.parseInt(SamaGamesAPI.get().getServerName().split("_")[1]));
        thisHub.setConnectedPlayers(this.hub.getServer().getOnlinePlayers().size());
        this.hub.getServer().getOnlinePlayers().forEach(thisHub::addConnectedPlayer);

        jedis.publish("hub-status", new Gson().toJson(thisHub));

        this.hubs.update();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

    jedis.close();

    this.hub.getGuiManager().getPlayersGui().keySet().stream().filter(uuid -> this.hub.getGuiManager().getPlayersGui().get(uuid) instanceof GuiSwitchHub).forEach(uuid -> this.hub.getGuiManager().getPlayersGui().get(uuid).update(this.hub.getServer().getPlayer(uuid)));
}
 
开发者ID:SamaGames,项目名称:Hub,代码行数:29,代码来源:HubRefresher.java

示例9: onStop

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public void onStop(Session session) {
    shiroSessionDao.delete(session);
    Jedis jedis = jedisPool.getResource();
    jedis.publish("shiro.session.uncache",(String) session.getId());
    logger.debug("session {} onStop", session.getId());
}
 
开发者ID:ZhuXS,项目名称:Spring-Shiro-Spark,代码行数:8,代码来源:ShiroSessionListener.java

示例10: onExpiration

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public void onExpiration(Session session) {
    shiroSessionDao.delete(session);
    Jedis jedis = jedisPool.getResource();
    jedis.publish("shiro.session.uncache",(String) session.getId());
    logger.debug("session {} onExpiration", session.getId());
}
 
开发者ID:ZhuXS,项目名称:Spring-Shiro-Spark,代码行数:8,代码来源:ShiroSessionListener.java

示例11: publish

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private boolean publish(String channel, String message) {
    Jedis jedis = null;
    try {
        jedis = pupJedisPool.getResource();
        return jedis.publish(channel, message) > 0;
    } finally {
        if (jedis != null) { jedis.close(); }
    }

}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:11,代码来源:Level1CacheSupport.java

示例12: deferExpired

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private void deferExpired() {
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        try {
            Jedis jedis = jedisPool.getResource();
            try {
                for (URL url : new HashSet<URL>(getRegistered())) {
                    if (url.getParameter(Constants.DYNAMIC_KEY, true)) {
                        String key = toCategoryPath(url);
                        if (jedis.hset(key, url.toFullString(), String.valueOf(System.currentTimeMillis() + expirePeriod)) == 1) {
                            jedis.publish(key, Constants.REGISTER);
                        }
                    }
                }
                if (admin) {
                    clean(jedis);
                }
                if (!replicate) {
                    break;//  如果服务器端已同步数据,只需写入单台机器
                }
            } finally {
                jedisPool.returnResource(jedis);
            }
        } catch (Throwable t) {
            logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
        }
    }
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:29,代码来源:RedisRegistry.java

示例13: doRegister

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public void doRegister(NURL nurl) {
    String key = toCategoryPath(nurl);
    String value = nurl.toFullString();
    String expire = String.valueOf(System.currentTimeMillis() + expirePeriod);
    boolean success = false;
    MregException exception = null;
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        try {
            Jedis jedis = jedisPool.getResource();
            try {
                jedis.hset(key, value, expire);
                jedis.publish(key, Consts.REGISTER);
                success = true;
                if (! replicate) {
                    break; //  如果服务器端已同步数据,只需写入单台机器
                }
            } catch (JedisConnectionException e){
            	logger.error("Jedis Connection Exception", e);
            } finally {
            	if(jedis != null){
                	jedis.close();
                }
            }
        } catch (Throwable t) {
            exception = new MregException("Failed to register service to redis registry. registry: " + entry.getKey() + ", service: " + nurl + ", cause: " + t.getMessage(), t);
        }
    }
    if (exception != null) {
        if (success) {
            logger.warn(exception.getMessage(), exception);
        } else {
            throw exception;
        }
    }
}
 
开发者ID:yu120,项目名称:coon,代码行数:38,代码来源:RedisMreg.java

示例14: clean

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private void clean(Jedis jedis) {
    Set<String> keys = jedis.keys(root + Consts.ANY_VALUE);
    if (keys != null && keys.size() > 0) {
        for (String key : keys) {
            Map<String, String> values = jedis.hgetAll(key);
            if (values != null && values.size() > 0) {
                boolean delete = false;
                long now = System.currentTimeMillis();
                for (Map.Entry<String, String> entry : values.entrySet()) {
                	NURL nurl = NURL.valueOf(entry.getKey());
                    if (nurl.getParameter(Consts.DYNAMIC_KEY, true)) {
                        long expire = Long.parseLong(entry.getValue());
                        if (expire < now) {
                            jedis.hdel(key, entry.getKey());
                            delete = true;
                            if (logger.isWarnEnabled()) {
                                logger.warn("Delete expired key: " + key + " -> value: " + entry.getKey() + ", expire: " + new Date(expire) + ", now: " + new Date(now));
                            }
                        }
                    }
                }
                if (delete) {
                    jedis.publish(key, Consts.UNREGISTER);
                }
            }
        }
    }
}
 
开发者ID:yu120,项目名称:coon,代码行数:29,代码来源:RedisMreg.java

示例15: handleClientOutputBufferLimitForSubscribeTooSlow

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test(expected = JedisConnectionException.class)
public void handleClientOutputBufferLimitForSubscribeTooSlow() throws InterruptedException {
  final Jedis j = createJedis();
  final AtomicBoolean exit = new AtomicBoolean(false);

  final Thread t = new Thread(new Runnable() {
    public void run() {
      try {

        // we already set jedis1 config to
        // client-output-buffer-limit pubsub 256k 128k 5
        // it means if subscriber delayed to receive over 256k or
        // 128k continuously 5 sec,
        // redis disconnects subscriber

        // we publish over 100M data for making situation for exceed
        // client-output-buffer-limit
        String veryLargeString = makeLargeString(10485760);

        // 10M * 10 = 100M
        for (int i = 0; i < 10 && !exit.get(); i++) {
          j.publish("foo", veryLargeString);
        }

        j.disconnect();
      } catch (Exception ex) {
      }
    }
  });
  t.start();
  try {
    jedis.subscribe(new JedisPubSub() {
      public void onMessage(String channel, String message) {
        try {
          // wait 0.5 secs to slow down subscribe and
          // client-output-buffer exceed
          // System.out.println("channel - " + channel +
          // " / message - " + message);
          Thread.sleep(100);
        } catch (Exception e) {
          try {
            t.join();
          } catch (InterruptedException e1) {
          }

          fail(e.getMessage());
        }
      }
    }, "foo");
  } finally {
    // exit the publisher thread. if exception is thrown, thread might
    // still keep publishing things.
    exit.set(true);
    if (t.isAlive()) {
      t.join();
    }
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:59,代码来源:PublishSubscribeCommandsTest.java


注:本文中的redis.clients.jedis.Jedis.publish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。