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


Java ShardedJedis.close方法代码示例

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


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

示例1: get

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
/**
 * 获取字符串
 */
@Override
public String get(String key) {
	ShardedJedis redis = null;
	String result = null;
	try {
		redis = pool.getResource();
		key = getKeyAll(key);
		result = redis.get(key);
		return result;
	} catch (RuntimeException e) { 
        if(redis != null ) {
			redis.close();
		}
        logger.error("redis get(String key):", e);
        return result;
	} finally{ 
           if(redis != null ) {
			redis.close();
		}
	}
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:25,代码来源:RedisCacheClient.java

示例2: run

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
public static <K> K run(byte[] key, Executor<K> executor, Integer... expire) {
    ShardedJedis jedis = getJedis();
    if (jedis == null) {
        return null;
    }
    try {
        K result = executor.execute(jedis);
        if (jedis.exists(key)) {
            if (expire == null || expire.length == 0) {
                jedis.expire(key, EXPIRE);
            } else if (expire.length == 1) {
                jedis.expire(key, expire[0]);
            }
        }
        return result;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
    return null;
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:25,代码来源:JedisTemplate.java

示例3: checkCloseable

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Test
public void checkCloseable() {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
  shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
  shards.get(0).setPassword("foobared");
  shards.get(1).setPassword("foobared");

  ShardedJedis jedisShard = new ShardedJedis(shards);
  try {
    jedisShard.set("shard_closeable", "true");
  } finally {
    jedisShard.close();
  }

  for (Jedis jedis : jedisShard.getAllShards()) {
    assertTrue(!jedis.isConnected());
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:20,代码来源:ShardedJedisTest.java

示例4: pushWhenNoRepeat

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Override
protected void pushWhenNoRepeat(Task task, Request request) {
    ShardedJedis jedis = jedisPool.getResource();
    try {
        String content = serializer.serialize(request);
        if(request.getPriority() == 0) {
            jedis.rpush(RedisKeys.getQueueNoPriorityKey(task), content);
        } else if (request.getPriority() > 0) {
            jedis.zadd(RedisKeys.getZsetPlusPriorityKey(task), request.getPriority(), content);
        } else {
            jedis.zadd(RedisKeys.getZsetMinusPriorityKey(task), request.getPriority(), content);
        }

        jedis.sadd(RedisKeys.getSetKey(task), request.key());
    } finally {
        jedis.close();
    }
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:19,代码来源:ShardedRedisPriorityScheduler.java

示例5: doPoll

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Override
public Request doPoll(Task task) {
    ShardedJedis jedis = jedisPool.getResource();
    try {
        String content = null;
        Set<String> contents = jedis.zrevrange(RedisKeys.getZsetPlusPriorityKey(task), 0, 0);
        if (contents != null && !contents.isEmpty()) {
            content = contents.toArray(new String[0])[0];
            jedis.zrem(RedisKeys.getZsetPlusPriorityKey(task), content);
        } else {
            content = jedis.lpop(RedisKeys.getQueueNoPriorityKey(task));
            if (StringUtils.isBlank(content)) {
                contents = jedis.zrevrange(RedisKeys.getZsetMinusPriorityKey(task), 0, 0);
                if (contents != null && !contents.isEmpty()) {
                    content = contents.toArray(new String[0])[0];
                    jedis.zrem(RedisKeys.getZsetPlusPriorityKey(task), content);
                }
            }
        }

        return StringUtils.isNotBlank(content) ? serializer.deserialize(content) : null;
    } finally {
        jedis.close();
    }
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:26,代码来源:ShardedRedisPriorityScheduler.java

示例6: get

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
public ShardedJedis get() throws JedisException {
    ShardedJedis jedis = context.get();
    if (jedis != null) { return jedis; }
    try {
        jedis = jedisPool.getResource();
    } catch (JedisException e) {
        if (jedis != null) {
            jedis.close();
        }
        throw e;
    }
    context.set(jedis);
    if (logger.isTraceEnabled()) {
        logger.trace(">>get a redis conn[{}]", jedis.toString());
    }
    return jedis;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:18,代码来源:JedisShardProvider.java

示例7: run

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
public <K> K run(byte[] key, Executor<K> executor, Integer... expire) {
	ShardedJedis jedis = getJedis();
	if (jedis == null) {
		return null;
	}
	try {
		K result = executor.execute(jedis);
		if (jedis.exists(key)) {
			if (expire == null || expire.length == 0) {
				jedis.expire(key, EXPIRE);
			} else if (expire.length == 1) {
				jedis.expire(key, expire[0]);
			}
		}
		return result;
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	} finally {
		if (jedis != null) {
			jedis.close();
		}
	}
	return null;
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:25,代码来源:JedisTemplate.java

示例8: setnx

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
/**
 * 从 Redis 2.6.12 版本开始, SET 命令的行为可以通过一系列参数来修改:
 * EX second :设置键的过期时间为 second 秒。 SET key value EX second 效果等同于 SETEX key second value 。
 * PX millisecond :设置键的过期时间为 millisecond 毫秒。 SET key value PX millisecond 效果等同于 PSETEX key millisecond value 。
 * NX :只在键不存在时,才对键进行设置操作。 SET key value NX 效果等同于 SETNX key value 。
 * XX :只在键已经存在时,才对键进行设置操作。
 *
 * @param key
 * @param value
 * @param milliseconds
 * @return
 */
public boolean setnx(String key, String value, long milliseconds) {
	ShardedJedis redis = null;
	try {
		redis = pool.getResource();
		key = getKeyAll(key);
		//nx|xx ex|px  seconds|milliseconds
		String result = redis.set(key, value, "nx", "px", milliseconds);
		return "OK".equalsIgnoreCase(result);
	} catch (RuntimeException e) {
		logger.error("redis setex(String key, int seconds, String value):", e);
		return false;
	} finally {
		redis.close();
	}
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:28,代码来源:RedisCacheClient.java

示例9: rename

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
/**
 * Use transactions to add index file and then delete the old one
 *
 * @param fileLengthKey the key using for hash file length
 * @param fileDataKey   the key using for hash file data
 * @param oldField      the old hash field
 * @param newField      the new hash field
 * @param values        the data values of the old hash field
 * @param fileLength    the data length of the old hash field
 */
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
        fileLength) {
    ShardedJedis shardedJedis = getShardedJedis();
    ShardedJedisPipeline pipelined = shardedJedis.pipelined();
    //add new file length
    pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
    //add new file content
    Long blockSize = getBlockSize(fileLength);
    for (int i = 0; i < blockSize; i++) {
        pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
    }
    pipelined.sync();
    shardedJedis.close();
    values.clear();
    deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:28,代码来源:ShardedJedisPoolStream.java

示例10: saveFile

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
    ShardedJedis shardedJedis = getShardedJedis();
    ShardedJedisPipeline pipelined = shardedJedis.pipelined();
    pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
    Long blockSize = getBlockSize(fileLength);
    for (int i = 0; i < blockSize; i++) {
        pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
        if (i % Constants.SYNC_COUNT == 0) {
            pipelined.sync();
            pipelined = shardedJedis.pipelined();
        }
    }
    pipelined.sync();
    shardedJedis.close();
    values.clear();
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:18,代码来源:ShardedJedisPoolStream.java

示例11: sort

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
public List<String> sort(String key) {
    List<String> result = null;
    ShardedJedis shardedJedis = shardedJedisPool.getResource();
    if (shardedJedis == null) {
        return null;
    }
    try {
        result = shardedJedis.sort(key);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        shardedJedis.close();
    }
    return result;
}
 
开发者ID:peng9627,项目名称:hall,代码行数:16,代码来源:RedisClientTemplate.java

示例12: getLeftCount

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Override
public int getLeftCount(Task task) {
    ShardedJedis jedis = jedisPool.getResource();
    try {
        Long size = jedis.llen(RedisKeys.getQueueKey(task));
        return size.intValue();
    } finally {
        jedis.close();
    }
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:11,代码来源:ShardedRedisScheduler.java

示例13: addRepeatCheck

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
@Override
public void addRepeatCheck(Task task, Request request) {
    ShardedJedis jedis = jedisPool.getResource();
    try {
        jedis.sadd(RedisKeys.getSetKey(task), request.key());
    } finally {
        jedis.close();
    }
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:10,代码来源:ShardedRedisScheduler.java

示例14: setex

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
/**
 * 存入字符串, 并设置失效时间
 */
@Override
public void setex(String key, int seconds, String value) {
	ShardedJedis redis = null;
	try {
		redis = pool.getResource();
		key = getKeyAll(key);
		redis.setex(key, seconds, value);
	} catch (RuntimeException e) {
		logger.error("redis setex(String key, int seconds, String value):", e);
	} finally{
		redis.close();
	}
	
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:18,代码来源:RedisCacheClient.java

示例15: getFirstVisitTime

import redis.clients.jedis.ShardedJedis; //导入方法依赖的package包/类
public long getFirstVisitTime(int shopId, String mac) {
    ShardedJedis jedis = JedisPoolManager.getResource();
    String key = shopId + "||" + mac;
    String firstVisitTime = jedis.lindex(key, 0);
    jedis.close();
    if (firstVisitTime == null) {
        return AnalysisConstants.DEFAULT_FIRST_VISIT_TIME;
    } else {
        return Long.valueOf(firstVisitTime);
    }
}
 
开发者ID:wanghan0501,项目名称:WiFiProbeAnalysis,代码行数:12,代码来源:UserVisitTimeDaoImpl.java


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