本文整理了Java中redis.clients.util.Pool.returnResource()
方法的一些代码示例,展示了Pool.returnResource()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Pool.returnResource()
方法的具体详情如下:
包路径:redis.clients.util.Pool
类名称:Pool
方法名:returnResource
暂无
代码示例来源:origin: sohutv/cachecloud
@Override
protected void returnResource(Jedis resource) {
super.returnResource(resource);
}
}
代码示例来源:origin: Dreampie/Resty
private void returnResource(ShardedJedis shardedJedis, Jedis jedis) {
if (pool != null) {
if (shardedJedis != null) {
pool.returnResource(shardedJedis);
}
if (jedis != null) {
pool.returnResource(jedis);
}
} else {
if (jedis != null) {
jedis.disconnect();
}
}
}
代码示例来源:origin: lindzh/hasting
@Override
public void returnResource(Jedis resource) {
redisPool.returnResource(resource);
}
代码示例来源:origin: penggle/jedis-ms-sentinel
protected void returnResource(I jedis){
if(jedis != null){
jedisPool.returnResource(jedis);
}
}
代码示例来源:origin: cn.dreampie/resty-cache
private void returnResource(ShardedJedis shardedJedis, Jedis jedis) {
if (pool != null) {
if (shardedJedis != null) {
pool.returnResource(shardedJedis);
}
if (jedis != null) {
pool.returnResource(jedis);
}
} else {
if (jedis != null) {
jedis.disconnect();
}
}
}
代码示例来源:origin: org.datanucleus/datanucleus-cache
@Override
public void evict(Object oid)
{
Jedis jedis = null;
try
{
jedis = pool.getResource();
jedis.del(getCacheKeyForId(oid).getBytes());
pool.returnResource(jedis);
}
catch (Exception e)
{
pool.returnBrokenResource(jedis);
throw new NucleusException(String.format("Failed to evict key %s from Redis cache", oid), e);
}
}
代码示例来源:origin: biz.paluch.logging/logstash-gelf
protected boolean sendMessage0(GelfMessage message) {
Jedis jedisClient = null;
try {
jedisClient = jedisPool.getResource();
jedisClient.lpush(redisKey, message.toJson(""));
return true;
} catch (Exception e) {
errorReporter.reportError(e.getMessage(), new IOException("Cannot send REDIS data with key URI " + redisKey, e));
return false;
} finally {
if (jedisClient != null) {
jedisPool.returnResource(jedisClient);
}
}
}
代码示例来源:origin: info.xiancloud/xian-gelf-common
protected boolean sendMessage0(GelfMessage message) {
Jedis jedisClient = null;
try {
jedisClient = jedisPool.getResource();
jedisClient.lpush(redisKey, message.toJson(""));
return true;
} catch (Exception e) {
errorReporter.reportError(e.getMessage(), new IOException("Cannot send REDIS data with key URI " + redisKey, e));
return false;
} finally {
if (jedisClient != null) {
jedisPool.returnResource(jedisClient);
}
}
}
代码示例来源:origin: org.datanucleus/datanucleus-cache
public void evict(Query query)
{
Jedis jedis = null;
String key = null;
try
{
jedis = pool.getResource();
key = QueryUtils.getKeyForQueryResultsCache(query, null);
jedis.del(key);
pool.returnResource(jedis);
}
catch (Exception e)
{
pool.returnBrokenResource(jedis);
throw new NucleusException(String.format("Failed to evict key %s from Redis cache", key), e);
}
}
代码示例来源:origin: org.datanucleus/datanucleus-cache
public void evict(Query query, Map params)
{
Jedis jedis = null;
String key = null;
try
{
jedis = pool.getResource();
key = QueryUtils.getKeyForQueryResultsCache(query, params);
jedis.del(key);
pool.returnResource(jedis);
}
catch (Exception e)
{
pool.returnBrokenResource(jedis);
throw new NucleusException(String.format("Failed to evict key %s from Redis cache", key), e);
}
}
代码示例来源:origin: org.datanucleus/datanucleus-cache
@Override
public CachedPC get(Object oid)
{
Jedis jedis = null;
Object value;
try
{
jedis = pool.getResource();
value = getObjectInternal(jedis.get(getCacheKeyForId(oid).getBytes()));
pool.returnResource(jedis);
}
catch (Exception e)
{
pool.returnBrokenResource(jedis);
throw new NucleusException(String.format("Failed to get key %s from cache {0}", oid), e);
}
return (CachedPC) value;
}
代码示例来源:origin: org.datanucleus/datanucleus-cache
public List<Object> put(String queryKey, List<Object> results)
{
if (queryKey == null || results == null)
{
return null;
}
Jedis jedis = null;
String key = KEY_PREFIX + queryKey;
try
{
jedis = pool.getResource();
jedis.setex(key.getBytes(), expirySeconds, getBytesForObject(results));
pool.returnResource(jedis);
}
catch (Exception e)
{
pool.returnBrokenResource(jedis);
throw new NucleusException(String.format("Failed to set object %s with ID %s into Redis cache", results, queryKey));
}
return results;
}
代码示例来源:origin: org.datanucleus/datanucleus-cache
@Override
public void evictAll()
{
Jedis jedis = null;
try
{
jedis = pool.getResource();
jedis.flushDB();
pool.returnResource(jedis);
}
catch (Exception e)
{
pool.returnBrokenResource(jedis);
throw new NucleusException("Failed to evict-all from Redis cache", e);
}
}
代码示例来源:origin: org.datanucleus/datanucleus-cache
public void evictAll()
{
Jedis jedis = null;
try
{
jedis = pool.getResource();
jedis.flushDB();
pool.returnResource(jedis);
}
catch (Exception e)
{
pool.returnBrokenResource(jedis);
throw new NucleusException("Failed to evict-all from Redis cache", e);
}
}
代码示例来源:origin: penggle/jedis-ms-sentinel
@Test
public void masterSlaveFailover() throws Exception {
Pool<ShardedMasterSlaveJedis> pool = this.getJedisPool();
ShardedMasterSlaveJedis shardedMasterSlaveJedis = pool.getResource();
System.out.println(">>> shardedMasterSlaveJedis = " + shardedMasterSlaveJedis);
pool.returnResource(shardedMasterSlaveJedis);
System.out.println("--------------------------------------");
shardedMasterSlaveJedis = pool.getResource();
System.out.println(">>> shardedMasterSlaveJedis = " + shardedMasterSlaveJedis);
pool.returnResource(shardedMasterSlaveJedis);
Thread.sleep(10L * 10);
shardedMasterSlaveJedis = pool.getResource();
System.out.println(">>> shardedMasterSlaveJedis = " + shardedMasterSlaveJedis);
pool.returnResource(shardedMasterSlaveJedis);
System.out.println("--------------------------------------");
pool.destroy();
}
代码示例来源:origin: penggle/jedis-ms-sentinel
public void close() {
if (dataSource != null) {
boolean broken = false;
for (MasterSlaveJedis jedis : getAllShards()) {
if (jedis.getClient().isBroken()) {
broken = true;
break;
}
}
if (broken) {
dataSource.returnBrokenResource(this);
} else {
dataSource.returnResource(this);
}
} else {
disconnect();
}
}
代码示例来源:origin: penggle/jedis-ms-sentinel
@Test
public void getRourceAndReturnResource(){
Pool<MasterSlaveJedis> pool = this.getJedisPool();
MasterSlaveJedis masterSlaveJedis = pool.getResource();
System.out.println(">>> masterSlaveJedis = " + masterSlaveJedis);
pool.returnResource(masterSlaveJedis);
System.out.println("--------------------------------------");
for(int i = 0; i < 10; i++){
masterSlaveJedis = pool.getResource();
Jedis slaveJedis = masterSlaveJedis.opsForSlave(String.valueOf(i));
System.out.println(">>> slaveJedis = " + slaveJedis.getClient().getHost() + ":" + slaveJedis.getClient().getPort());
pool.returnResource(masterSlaveJedis);
}
System.out.println("--------------------------------------");
System.out.println(">>> pool = " + pool);
pool.destroy();
System.out.println(">>> pool = " + pool);
System.out.println(pool.getResource());// 如果pool已经被销毁,调用pool.getResource()会抛出"Can not get a resource from pool"异常
}
代码示例来源:origin: penggle/jedis-ms-sentinel
@Test
public void getResource() throws Exception {
Jedis master = null;
try {
master = this.getJedisPool().getResource();
System.out.println(String.format(">>> jedis = %s", master));
System.out.println(master.getClient().getHost() + ":" + master.getClient().getPort());
//System.out.println(jedis.info()); //看以看出此处的jedis实例指向的是master
Date now = new Date();
master.set("current_time", String.format("%tF %tT", now, now));
master.incr("COUNT");
} finally {
if(master != null){
this.getJedisPool().returnResource(master);
}
}
}
代码示例来源:origin: penggle/jedis-ms-sentinel
@Test
public void masterSetSlaveGet(){
Date now = new Date();
String nowTime = String.format("%tF %tT", now, now);
Pool<MasterSlaveJedis> pool = this.getJedisPool();
MasterSlaveJedis masterSlaveJedis = pool.getResource();
System.out.println(">>> masterSlaveJedis = " + masterSlaveJedis.getClient().getHost() + ":" + masterSlaveJedis.getClient().getPort());
System.out.println(">>> nowTime = " + nowTime);
masterSlaveJedis.set("current_time", nowTime);
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(200));
System.out.println("--------------------------------------");
Jedis slaveJedis = masterSlaveJedis.opsForSlave();
System.out.println(">>> slaveJedis = " + slaveJedis.getClient().getHost() + ":" + slaveJedis.getClient().getPort());
System.out.println(">>> nowTime = " + slaveJedis.get("current_time"));
//slaveJedis.set("current_time", nowTime + ".000"); // slave节点默认是只读的,如果在只读的slave节点上进行写操作会抛出异常
pool.returnResource(masterSlaveJedis);
System.out.println("--------------------------------------");
pool.destroy();
}
代码示例来源:origin: penggle/jedis-ms-sentinel
@Test
public void masterSlaveFailover() throws Exception {
Pool<MasterSlaveJedis> pool = this.getJedisPool();
MasterSlaveJedis masterSlaveJedis = pool.getResource();
System.out.println(">>> masterSlaveJedis = " + masterSlaveJedis.getClient().getHost() + ":" + masterSlaveJedis.getClient().getPort());
pool.returnResource(masterSlaveJedis);
System.out.println("--------------------------------------");
masterSlaveJedis = pool.getResource();
System.out.println(">>> masterSlaveJedis = " + masterSlaveJedis.getClient().getHost() + ":" + masterSlaveJedis.getClient().getPort());
pool.returnResource(masterSlaveJedis);
Thread.sleep(120000L * 10);
masterSlaveJedis = pool.getResource();
System.out.println(">>> masterSlaveJedis = " + masterSlaveJedis.getClient().getHost() + ":" + masterSlaveJedis.getClient().getPort());
pool.returnResource(masterSlaveJedis);
System.out.println("--------------------------------------");
pool.destroy();
}
内容来源于网络,如有侵权,请联系作者删除!