當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。