本文整理匯總了Java中redis.clients.jedis.exceptions.JedisException類的典型用法代碼示例。如果您正苦於以下問題:Java JedisException類的具體用法?Java JedisException怎麽用?Java JedisException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JedisException類屬於redis.clients.jedis.exceptions包,在下文中一共展示了JedisException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: zadd
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
@Override public Long zadd(final String key, final Map<String, Double> scoreMembers) {
try {
Double score = null;
String member = null;
List<ZsetPair> scoresmembers = new ArrayList<ZsetPair>((scoreMembers.size() - 1)*2);
for (String m : scoreMembers.keySet()) {
if (m == null) {
member = m;
score = scoreMembers.get(m);
continue;
}
scoresmembers.add(new ZsetPair(m, scoreMembers.get(m)));
}
return redis.zadd(key, new ZsetPair(member, score), (ZsetPair[])scoresmembers.toArray());
}
catch (Exception e) {
throw new JedisException(e);
}
}
示例2: get
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
public Jedis get() throws JedisException {
Jedis 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[{}],Host:{}", jedis.toString(), jedis.getClient().getHost());
}
return jedis;
}
示例3: get
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
public Jedis get() throws JedisException {
Jedis 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[{}],Host:{}", jedis.toString(),
jedis.getClient().getHost());
}
return jedis;
}
示例4: get
import redis.clients.jedis.exceptions.JedisException; //導入依賴的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;
}
示例5: remove
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
@Override
public String remove(@NotNull String key) {
if (key == null) {
throw new IllegalArgumentException("Cannot remove null key");
}
String rKey = redisKey(storeName, key);
try (Jedis jedis = pool.getResource()) {
String previousValue = jedis.get(rKey);
jedis.del(rKey);
return previousValue;
} catch (JedisException e) {
redisIsHealthy = false;
String msg = String.format("Unable to remove key %s (Redis key %s)", key, rKey);
LOG.error(msg);
throw new RuntimeException(msg, e);
}
}
示例6: get
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
@Override
public String get(@NotNull String key) {
if (key == null) {
throw new IllegalArgumentException("Cannot get null key");
}
String rKey = redisKey(storeName, key);
try (Jedis jedis = pool.getResource()) {
return jedis.get(rKey);
} catch (JedisException e) {
redisIsHealthy = false;
String msg = String.format("Unable to get key %s (Redis key %s)", key, rKey);
LOG.error(msg);
throw new RuntimeException(e);
}
}
示例7: mget
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
public JsonArray mget(String...keys) {
try(Context context = mgetTimer.time()) {
JsonArray results=array();
try(Jedis resource = jedisPool.getResource()) {
byte[][] byteKeys = Arrays.stream(keys).map(key -> key(key)).toArray(size -> new byte[size][]);
List<byte[]> redisResults = resource.mget(byteKeys);
if(redisResults!=null) {
for(byte[] blob:redisResults) {
if(blob != null) {
// some results will be null
results.add(parser.parseObject(new String(CompressionUtils.decompress(blob), utf8)));
}
}
}
} catch (JedisException e) {
// make sure we can find back jedis related stuff in kibana
throw new IllegalStateException("problem connecting to jedis", e);
}
notFoundMeter.mark();
return results;
}
}
示例8: get
import redis.clients.jedis.exceptions.JedisException; //導入依賴的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;
}
示例9: updateKafkaLogEvent
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
public static boolean updateKafkaLogEvent(int unixtime, final String event){
Date date = new Date(unixtime*1000L);
final String dateStr = DateTimeUtil.formatDate(date ,DATE_FORMAT_PATTERN);
final String dateHourStr = DateTimeUtil.formatDate(date ,YYYY_MM_DD_HH);
boolean commited = new RedisCommand<Boolean>(jedisPool) {
@Override
protected Boolean build() throws JedisException {
String keyD = MONITOR_PREFIX+dateStr;
String keyH = MONITOR_PREFIX+dateHourStr;
Pipeline p = jedis.pipelined();
p.hincrBy(keyD, "e:"+event , 1L);
p.expire(keyD, AFTER_4_DAYS);
p.hincrBy(keyH, "e:"+event , 1L);
p.expire(keyH, AFTER_2_DAYS);
p.sync();
return true;
}
}.execute();
return commited;
}
示例10: makeObject
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
@Override
public PooledObject<Jedis> makeObject() throws Exception {
final HostAndPort hostAndPort = this.hostAndPort.get();
JaRedis.Builder builder = new JaRedis.Builder();
builder
.host(hostAndPort.getHost())
.port(hostAndPort.getPort())
.connectionTimeout(connectionTimeout)
.soTimeout(soTimeout);
Jedis jedis = builder.build();
try {
jedis.connect();
if (null != this.password) {
jedis.auth(this.password);
}
if (database != 0) {
jedis.select(database);
}
if (clientName != null) {
jedis.clientSetname(clientName);
}
} catch (JedisException je) {
jedis.close();
throw je;
}
return new DefaultPooledObject<>(jedis);
}
示例11: getResource
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
/**
* 獲取資源
*
* @return
* @throws JedisException
*/
public static Jedis getResource() throws JedisException {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
// logger.debug("getResource.", jedis);
} catch (JedisException e) {
logger.warn("getResource.", e);
returnBrokenResource(jedis);
throw e;
}
return jedis;
}
示例12: getConnection
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
@Override
public Jedis getConnection() {
// In antirez's redis-rb-cluster implementation,
// getRandomConnection always return valid connection (able to
// ping-pong)
// or exception if all connections are invalid
List<JedisPool> pools = cache.getShuffledNodesPool();
for (JedisPool pool : pools) {
Jedis jedis = null;
try {
jedis = pool.getResource();
if (jedis == null) {
continue;
}
String result = jedis.ping();
if (result.equalsIgnoreCase("pong")) {
return jedis;
}
jedis.close();
} catch (JedisException ex) {
if (jedis != null) {
jedis.close();
}
}
}
throw new JedisNoReachableClusterNodeException("No reachable node in cluster");
}
示例13: makeObject
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
@Override
public PooledObject<Jedis> makeObject() throws Exception {
final HostAndPort hostAndPort = this.hostAndPort.get();
final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), connectionTimeout, soTimeout,
password, database, ssl, sslSocketFactory, sslParameters, hostnameVerifier);
try {
jedis.connect();
//if (password != null && !password.isEmpty()) {
// jedis.auth(password);
//}
//if (database != 0) {
// jedis.select(database);
//}
if (clientName != null) {
String reply = jedis.clientSetname(clientName);
if (!"OK".equalsIgnoreCase(reply)) {
logger.info("reply={}",reply);
}
}
} catch (JedisException je) {
jedis.close();
throw je;
}
return new DefaultPooledObject<Jedis>(jedis);
}
示例14: returnResource
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
/**
* @deprecated starting from Jedis 3.0 this method will not be exposed. Resource
* cleanup should be done using @see
* {@link redis.clients.jedis.Jedis#close()}
*/
@Override
@Deprecated
public void returnResource(final Jedis resource) {
if (resource != null) {
try {
resource.resetState();
returnResourceObject(resource);
} catch (Exception e) {
returnBrokenResource(resource);
throw new JedisException("Could not return the resource to the pool", e);
}
}
}
示例15: encode
import redis.clients.jedis.exceptions.JedisException; //導入依賴的package包/類
public static byte[] encode(final String str) {
try {
if (str == null) {
throw new JedisDataException("value sent to redis cannot be null");
}
return str.getBytes(Protocol.CHARSET);
} catch (UnsupportedEncodingException e) {
throw new JedisException(e);
}
}