@Override public Boolean expire(byte[] key, long seconds) { Assert.notNull(key, "Key must not be null!"); if (seconds > Integer.MAX_VALUE) { return pExpire(key, TimeUnit.SECONDS.toMillis(seconds)); } try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().expire(key, (int) seconds), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().expire(key, (int) seconds), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().expire(key, (int) seconds)); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } }
private void expire0(String key, int seconds) { t.expire(key, seconds); }
@Override public Object execute(Jedis jedis) { Transaction transaction = jedis.multi(); for (int i = 0; i < keyList.size(); i++) { transaction.append(keyList.get(i), valueList.get(i)); transaction.expire(keyList.get(i), seconds); } transaction.exec(); return true; } });
@SuppressWarnings({"unchecked", "rawtypes"}) @Override public void put(Object key, Object value) { if (isInTransaction()) { if (value instanceof Map) { transaction.hmset(key.toString(), (Map)value); } else { transaction.set(key.toString(), value.toString()); } if (keyExpiryTime != -1) { transaction.expire(key.toString(), keyExpiryTime); } } else { if (value instanceof Map) { jedis.hmset(key.toString(), (Map)value); } else { jedis.set(key.toString(), value.toString()); } if (keyExpiryTime != -1) { jedis.expire(key.toString(), keyExpiryTime); } } }
@SuppressWarnings({"unchecked", "rawtypes"}) @Override public void put(Object key, Object value) { if (isInTransaction()) { if (value instanceof Map) { transaction.hmset(key.toString(), (Map) value); } else { transaction.set(key.toString(), value.toString()); } if (keyExpiryTime != -1) { transaction.expire(key.toString(), keyExpiryTime); } } else { if (value instanceof Map) { jedis.hmset(key.toString(), (Map) value); } else { jedis.set(key.toString(), value.toString()); } if (keyExpiryTime != -1) { jedis.expire(key.toString(), keyExpiryTime); } } }
@Override public Object execute(Jedis jedis) { Transaction transaction = jedis.multi(); transaction.append(key, value); transaction.expire(key, seconds); transaction.exec(); return true; } });
/** * Calls hincrbyfloat on the redis store. * * @param key * @param field * @param doubleValue */ public void hincrByFloat(String key, String field, double doubleValue) { if (isInTransaction()) { transaction.hincrByFloat(key, field, doubleValue); if (keyExpiryTime != -1) { transaction.expire(key, keyExpiryTime); } } else { jedis.hincrByFloat(key, field, doubleValue); if (keyExpiryTime != -1) { jedis.expire(key, keyExpiryTime); } } }
/** * Calls incrbyfloat on the redis store. * * @param key * @param doubleValue */ public void incrByFloat(String key, double doubleValue) { if (isInTransaction()) { transaction.incrByFloat(key, doubleValue); if (keyExpiryTime != -1) { transaction.expire(key, keyExpiryTime); } } else { jedis.incrByFloat(key, doubleValue); if (keyExpiryTime != -1) { jedis.expire(key, keyExpiryTime); } } }
/** * Calls incrbyfloat on the redis store. * * @param key * @param doubleValue */ public void incrByFloat(String key, double doubleValue) { if (isInTransaction()) { transaction.incrByFloat(key, doubleValue); if (keyExpiryTime != -1) { transaction.expire(key, keyExpiryTime); } } else { jedis.incrByFloat(key, doubleValue); if (keyExpiryTime != -1) { jedis.expire(key, keyExpiryTime); } } }
/** * Calls hincrbyfloat on the redis store. * * @param key * @param field * @param doubleValue */ public void hincrByFloat(String key, String field, double doubleValue) { if (isInTransaction()) { transaction.hincrByFloat(key, field, doubleValue); if (keyExpiryTime != -1) { transaction.expire(key, keyExpiryTime); } } else { jedis.hincrByFloat(key, field, doubleValue); if (keyExpiryTime != -1) { jedis.expire(key, keyExpiryTime); } } }
@Override public void action(Transaction trans) { Integer nextMessageId = getNextMessageId(); String msgKey = topic.cat("message").cat(nextMessageId).key(); if (message instanceof String) { trans.set(msgKey, (String) message); } else { trans.set(msgKey.getBytes(), SerializableKit.toByteArray(message)); } Logger.info("produce a message,key[" + msgKey + "],message[" + message + "]"); trans.set(topic.key(), nextMessageId.toString()); if (seconds > 0) { trans.expire(msgKey, seconds); } } });
tr.expire(redisKey, exp); //expire after exp seconds
/** * * @param message * menssage * @param seconds * expiry time */ public void publish(String message, int seconds) { List<Object> exec = null; Integer lastMessageId = null; do { topic.watch(); lastMessageId = getNextMessageId(); Transaction trans = jedis.multi(); String msgKey = topic.cat("message").cat(lastMessageId).key(); trans.set(msgKey, message); trans.set(topic.key(), lastMessageId.toString()); if (seconds > 0) trans.expire(msgKey, seconds); exec = trans.exec(); } while (exec == null); } }
@Override public Boolean expire(byte[] key, long seconds) { Assert.notNull(key, "Key must not be null!"); if (seconds > Integer.MAX_VALUE) { return pExpire(key, TimeUnit.SECONDS.toMillis(seconds)); } try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().expire(key, (int) seconds), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().expire(key, (int) seconds), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().expire(key, (int) seconds)); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } }
@Override public Boolean expire(byte[] key, long seconds) { Assert.notNull(key, "Key must not be null!"); if (seconds > Integer.MAX_VALUE) { return pExpire(key, TimeUnit.SECONDS.toMillis(seconds)); } try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().expire(key, (int) seconds), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().expire(key, (int) seconds), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().expire(key, (int) seconds)); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } }