本文整理汇总了Java中redis.clients.jedis.Jedis.close方法的典型用法代码示例。如果您正苦于以下问题:Java Jedis.close方法的具体用法?Java Jedis.close怎么用?Java Jedis.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sentinelMonitor
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void sentinelMonitor() {
Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
try {
// monitor new master
String result = j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, master.getPort(), 1);
assertEquals("OK", result);
// already monitored
try {
j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, master.getPort(), 1);
fail();
} catch (JedisDataException e) {
// pass
}
} finally {
j.close();
}
}
示例2: get
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public String get(String key) {
Jedis jedis = null;
String result = "";
try {
jedis = getJedis();
if (jedis != null) {
result = jedis.get(key);
} else {
logger.error("get opt connection null error!");
}
} catch (JedisConnectionException e) {
if (jedis != null) {
jedis.close();
jedis = null;
}
logger.error("get value connect error:", e);
} finally {
returnJedisResource(jedis);
}
return result;
}
示例3: exists
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 判断是否存在
* @param existskey
* @return
*/
public boolean exists(String existskey) throws Exception {
Jedis jds = null;
try {
jds = getJedis();
jds.select(0);
return jds.exists(existskey.getBytes());
} catch (Exception e) {
throw e;
} finally {
if(jds != null)
{
jds.close();
}
}
}
示例4: getAllService
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取所有服务列表
*/
public List<String> getAllService(){
Jedis jedis = JedisTemplate.getJedis();
List<String> services = null;
try{
services = jedis.lrange(onlineServices, 0, -1);
}catch(Exception e){
e.printStackTrace();
}finally{
jedis.close();
}
return services;
}
示例5: test_jedis_proxy
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void test_jedis_proxy() {
JedisPoolConfig config = new JedisPoolConfig();
JaRedisPool pool = new JaRedisPool(config, "127.0.0.1", 6379);
Jedis jedis = pool.getResource();
jedis.set("hello", "world");
Assert.assertEquals(jedis.get("hello"), "world");
jedis.close();
}
示例6: flushConfig
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 清空配置.
* @param name 应用opkind
* @throws Exception Exception
*/
public void flushConfig(final String name) throws Exception{
Jedis configJedis = o2iJedisPool.getResource();
Set<String> configSet = configJedis.keys(name+"*");
if(!CollectionUtils.isEmpty(configSet)){
configJedis.del(configSet.toArray(new String[0]));
}
configJedis.close();
}
示例7: set
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public String set(String key, String value) {
Jedis jedis = jedisPool.getResource();
String result = jedis.set(key, value);
jedis.close();
return result;
}
示例8: hexists
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public Boolean hexists(String key, String field) {
Jedis jedis = jedisPool.getResource();
Boolean result = jedis.hexists(key, field);
jedis.close();
return result;
}
示例9: get
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取String值
* @param key
* @return value
*/
public synchronized static String get(String key) {
Jedis jedis = getJedis();
if (null == jedis) {
return null;
}
String value = jedis.get(key);
jedis.close();
return value;
}
示例10: sadd
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* sadd
* @param key
* @param value
* @param seconds
*/
public synchronized static void sadd(String key, String value, int seconds) {
try {
Jedis jedis = RedisUtil.getJedis();
jedis.sadd(key, value);
jedis.expire(key, seconds);
jedis.close();
} catch (Exception e) {
_log.error("sadd error : " + e);
}
}
示例11: remove
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 删除值
* @param key
*/
public synchronized static void remove(String key) {
try {
Jedis jedis = getJedis();
jedis.del(key);
jedis.close();
} catch (Exception e) {
LOGGER.error("Remove keyex error : " + e);
}
}
示例12: returnResourceShouldResetState
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void returnResourceShouldResetState() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
"foobared", 2);
Jedis jedis = pool.getResource();
Jedis jedis2 = null;
try {
jedis.set("hello", "jedis");
Transaction t = jedis.multi();
t.set("hello", "world");
pool.returnResource(jedis);
jedis2 = pool.getResource();
assertTrue(jedis == jedis2);
assertEquals("jedis", jedis2.get("hello"));
} catch (JedisConnectionException e) {
if (jedis2 != null) {
pool.returnBrokenResource(jedis2);
jedis2 = null;
}
} finally {
if (jedis2 != null) jedis2.close();
pool.destroy();
}
}
示例13: eval
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* Eval lua script command
*
* @param script
* @param keys
* @param args
* @return
*/
public Object eval(String script, List<String> keys, List<String> args) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.eval(script, keys, args);
} finally {
if (jedis != null) {
jedis.close();
}
}
}
示例14: getStringStringMap
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private Map<String, String> getStringStringMap(String index) {
Jedis jedis = getJedis();
MapStructure<String> mapStructure = RedisStrutureBuilder.ofMap(jedis, String.class).withNameSpace(nameSpace).build();
Map<String, String> map = mapStructure.get(index);
Map<String, String> result = new HashMap<>();
result.putAll(map);
if (jedis != null) {
jedis.close();
}
return result;
}
示例15: get
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public static Object get(String key) {
Object reval = null;
Jedis jedis = null;
try {
jedis = pool.getResource();
reval = jedis.get(key);
} catch (Exception e) {
LOG.info("Error, idle : " + pool.getNumIdle() + ", active : " + pool.getNumActive() + ", waiter : " + pool.getNumWaiters());
} finally {
if(jedis != null) jedis.close();
}
return reval;
}