本文整理了Java中redis.clients.jedis.Jedis.publish()
方法的一些代码示例,展示了Jedis.publish()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.publish()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:publish
暂无
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.publish(channel, message);
}
}.runWithAnyNode();
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.publish(channel, message);
}
}.runWithAnyNode();
代码示例来源:origin: caoxinyu/RedisClient
@Override
protected void command() {
jedis.publish(channel, message);
}
代码示例来源:origin: zendesk/maxwell
private void sendToRedis(String msg) {
switch (redistype) {
case "lpush":
jedis.lpush(this.listkey, msg);
break;
case "pubsub":
default:
jedis.publish(this.channel, msg);
break;
}
this.succeededMessageCount.inc();
this.succeededMessageMeter.mark();
}
代码示例来源:origin: signalapp/Signal-Server
private boolean publish(byte[] channel, PubSubMessage message) {
try (Jedis jedis = jedisPool.getWriteResource()) {
long result = jedis.publish(channel, message.toByteArray());
if (result < 0) {
logger.warn("**** Jedis publish result < 0");
}
return result > 0;
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void doRegister(URL url) {
String key = toCategoryPath(url);
String value = url.toFullString();
String expire = String.valueOf(System.currentTimeMillis() + expirePeriod);
boolean success = false;
RpcException exception = null;
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
try (Jedis jedis = jedisPool.getResource()) {
jedis.hset(key, value, expire);
jedis.publish(key, Constants.REGISTER);
success = true;
if (!replicate) {
break; // If the server side has synchronized data, just write a single machine
}
}
} catch (Throwable t) {
exception = new RpcException("Failed to register service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
if (exception != null) {
if (success) {
logger.warn(exception.getMessage(), exception);
} else {
throw exception;
}
}
}
代码示例来源:origin: apache/incubator-dubbo
private void deferExpired() {
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
try (Jedis jedis = jedisPool.getResource()) {
for (URL url : new HashSet<>(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;// If the server side has synchronized data, just write a single machine
}
}
} catch (Throwable t) {
logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
}
}
}
代码示例来源:origin: apache/incubator-dubbo
private void deferExpired() {
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
try (Jedis jedis = jedisPool.getResource()) {
for (URL url : new HashSet<>(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;// If the server side has synchronized data, just write a single machine
}
}
} catch (Throwable t) {
logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void doRegister(URL url) {
String key = toCategoryPath(url);
String value = url.toFullString();
String expire = String.valueOf(System.currentTimeMillis() + expirePeriod);
boolean success = false;
RpcException exception = null;
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
try (Jedis jedis = jedisPool.getResource()) {
jedis.hset(key, value, expire);
jedis.publish(key, Constants.REGISTER);
success = true;
if (!replicate) {
break; // If the server side has synchronized data, just write a single machine
}
}
} catch (Throwable t) {
exception = new RpcException("Failed to register service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
if (exception != null) {
if (success) {
logger.warn(exception.getMessage(), exception);
} else {
throw exception;
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void doUnregister(URL url) {
String key = toCategoryPath(url);
String value = url.toFullString();
RpcException exception = null;
boolean success = false;
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
try (Jedis jedis = jedisPool.getResource()) {
jedis.hdel(key, value);
jedis.publish(key, Constants.UNREGISTER);
success = true;
if (!replicate) {
break; // If the server side has synchronized data, just write a single machine
}
}
} catch (Throwable t) {
exception = new RpcException("Failed to unregister service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
if (exception != null) {
if (success) {
logger.warn(exception.getMessage(), exception);
} else {
throw exception;
}
}
}
代码示例来源:origin: apache/incubator-dubbo
private void clean(Jedis jedis) {
Set<String> keys = jedis.keys(root + Constants.ANY_VALUE);
if (CollectionUtils.isNotEmpty(keys)) {
for (String key : keys) {
Map<String, String> values = jedis.hgetAll(key);
if (CollectionUtils.isNotEmptyMap(values)) {
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);
}
}
}
}
}
代码示例来源:origin: apache/incubator-dubbo
private void clean(Jedis jedis) {
Set<String> keys = jedis.keys(root + Constants.ANY_VALUE);
if (CollectionUtils.isNotEmpty(keys)) {
for (String key : keys) {
Map<String, String> values = jedis.hgetAll(key);
if (CollectionUtils.isNotEmptyMap(values)) {
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);
}
}
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void doUnregister(URL url) {
String key = toCategoryPath(url);
String value = url.toFullString();
RpcException exception = null;
boolean success = false;
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
try (Jedis jedis = jedisPool.getResource()) {
jedis.hdel(key, value);
jedis.publish(key, Constants.UNREGISTER);
success = true;
if (!replicate) {
break; // If the server side has synchronized data, just write a single machine
}
}
} catch (Throwable t) {
exception = new RpcException("Failed to unregister service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
if (exception != null) {
if (success) {
logger.warn(exception.getMessage(), exception);
} else {
throw exception;
}
}
}
代码示例来源:origin: sohutv/cachecloud
/**
* @param channel
* @param message
* @return
*/
public Long publish(final String channel, final String message) {
SubPubClusterCommand subPubClusterCommand = new SubPubClusterCommand(this, connectionHandler, maxRedirections);
Jedis jedis = subPubClusterCommand.getJedis(channel);
try {
return jedis.publish(channel, message);
} finally {
subPubClusterCommand.releaseConnection(jedis);
}
}
代码示例来源:origin: sohutv/cachecloud
/**
* @param channel
* @param message
* @return
*/
public Long publish(final String channel, final byte[] message) {
SubPubClusterCommand subPubClusterCommand = new SubPubClusterCommand(this, connectionHandler, maxRedirections);
Jedis jedis = subPubClusterCommand.getJedis(channel);
try {
return jedis.publish(SafeEncoder.encode(channel), message);
} finally {
subPubClusterCommand.releaseConnection(jedis);
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
private void deferExpired() {
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
Jedis jedis = jedisPool.getResource();
try {
for (Node node : new HashSet<Node>(getRegistered())) {
String key = NodeRegistryUtils.getNodeTypePath(clusterName, node.getNodeType());
if (jedis.hset(key, node.toFullString(), String.valueOf(SystemClock.now() + expirePeriod)) == 1) {
jedis.publish(key, Constants.REGISTER);
}
}
if (lock.acquire(jedis)) {
clean(jedis);
}
if (!replicate) {
break;// 如果服务器端已同步数据,只需写入单台机器
}
} finally {
jedis.close();
}
} catch (Throwable t) {
LOGGER.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
}
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
private void deferExpired() {
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
Jedis jedis = jedisPool.getResource();
try {
for (Node node : new HashSet<Node>(getRegistered())) {
String key = NodeRegistryUtils.getNodeTypePath(clusterName, node.getNodeType());
if (jedis.hset(key, node.toFullString(), String.valueOf(SystemClock.now() + expirePeriod)) == 1) {
jedis.publish(key, Constants.REGISTER);
}
}
if (lock.acquire(jedis)) {
clean(jedis);
}
if (!replicate) {
break;// 如果服务器端已同步数据,只需写入单台机器
}
} finally {
jedis.close();
}
} catch (Throwable t) {
LOGGER.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
}
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
try {
jedis.hdel(key, node.toFullString());
jedis.publish(key, Constants.UNREGISTER);
success = true;
if (!replicate) {
代码示例来源:origin: ltsopensource/light-task-scheduler
try {
jedis.hset(key, node.toFullString(), expire);
jedis.publish(key, Constants.REGISTER);
success = true;
if (!replicate) {
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Long publish(byte[] channel, byte[] message) {
try {
if (isPipelined()) {
pipeline(newJedisResult(getRequiredPipeline().publish(channel, message)));
return null;
}
if (isQueueing()) {
transaction(newJedisResult(getRequiredTransaction().publish(channel, message)));
return null;
}
return jedis.publish(channel, message);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
内容来源于网络,如有侵权,请联系作者删除!