/** * Executes the Redis restore command. The value passed in should be the exact serialized data returned from * {@link #dump(Object)}, since Redis uses a non-standard serialization mechanism. * * @param key The key to restore * @param value The value to restore, as returned by {@link #dump(Object)} * @param timeToLive An expiration for the restored key, or 0 for no expiration * @param unit The time unit for timeToLive * @param replace use {@literal true} to replace a potentially existing value instead of erroring. * @throws RedisSystemException if the key you are attempting to restore already exists and {@code replace} is set to * {@literal false}. */ @Override public void restore(K key, final byte[] value, long timeToLive, TimeUnit unit, boolean replace) { byte[] rawKey = rawKey(key); long rawTimeout = TimeoutUtils.toMillis(timeToLive, unit); execute(connection -> { connection.restore(rawKey, rawTimeout, value, replace); return null; }, true); }
@Override public Boolean expire(K key, final long timeout, final TimeUnit unit) { byte[] rawKey = rawKey(key); long rawTimeout = TimeoutUtils.toMillis(timeout, unit); return execute(connection -> { try { return connection.pExpire(rawKey, rawTimeout); } catch (Exception e) { // Driver may not support pExpire or we may be running on Redis 2.4 return connection.expire(rawKey, TimeoutUtils.toSeconds(timeout, unit)); } }, true); }
public void putRedis( byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, long timeout,TimeUnit unit) { final byte[] paramArrayOfByte1Tmp = paramArrayOfByte1; final byte[] paramArrayOfByte2Tmp = paramArrayOfByte2; final long timeOutTmp = timeout; final TimeUnit unitTmp = unit; final long rawTimeout = TimeoutUtils.toMillis(timeout, unit); stringRedisTemplate.execute(new RedisCallback<Object>() { @Override public Object doInRedis(RedisConnection redisConnection) throws DataAccessException { redisConnection.set(paramArrayOfByte1Tmp,paramArrayOfByte2Tmp); stringRedisTemplate.execute(new RedisCallback() { public Boolean doInRedis(RedisConnection connection) { try { return connection.pExpire(paramArrayOfByte1Tmp, rawTimeout); } catch (Exception var3) { return connection.expire(paramArrayOfByte1Tmp, TimeoutUtils.toSeconds(timeOutTmp, unitTmp)); } } },true); return null; } },true); }
/** * Executes the Redis restore command. The value passed in should be the exact serialized data returned from * {@link #dump(Object)}, since Redis uses a non-standard serialization mechanism. * * @param key The key to restore * @param value The value to restore, as returned by {@link #dump(Object)} * @param timeToLive An expiration for the restored key, or 0 for no expiration * @param unit The time unit for timeToLive * @param replace use {@literal true} to replace a potentially existing value instead of erroring. * @throws RedisSystemException if the key you are attempting to restore already exists and {@code replace} is set to * {@literal false}. */ @Override public void restore(K key, final byte[] value, long timeToLive, TimeUnit unit, boolean replace) { byte[] rawKey = rawKey(key); long rawTimeout = TimeoutUtils.toMillis(timeToLive, unit); execute(connection -> { connection.restore(rawKey, rawTimeout, value, replace); return null; }, true); }
/** * Executes the Redis restore command. The value passed in should be the exact serialized data returned from * {@link #dump(Object)}, since Redis uses a non-standard serialization mechanism. * * @param key The key to restore * @param value The value to restore, as returned by {@link #dump(Object)} * @param timeToLive An expiration for the restored key, or 0 for no expiration * @param unit The time unit for timeToLive * @param replace use {@literal true} to replace a potentially existing value instead of erroring. * @throws RedisSystemException if the key you are attempting to restore already exists and {@code replace} is set to * {@literal false}. */ @Override public void restore(K key, final byte[] value, long timeToLive, TimeUnit unit, boolean replace) { byte[] rawKey = rawKey(key); long rawTimeout = TimeoutUtils.toMillis(timeToLive, unit); execute(connection -> { connection.restore(rawKey, rawTimeout, value, replace); return null; }, true); }
@Override public Boolean expire(K key, final long timeout, final TimeUnit unit) { byte[] rawKey = rawKey(key); long rawTimeout = TimeoutUtils.toMillis(timeout, unit); return execute(connection -> { try { return connection.pExpire(rawKey, rawTimeout); } catch (Exception e) { // Driver may not support pExpire or we may be running on Redis 2.4 return connection.expire(rawKey, TimeoutUtils.toSeconds(timeout, unit)); } }, true); }
@Override public Boolean expire(K key, final long timeout, final TimeUnit unit) { byte[] rawKey = rawKey(key); long rawTimeout = TimeoutUtils.toMillis(timeout, unit); return execute(connection -> { try { return connection.pExpire(rawKey, rawTimeout); } catch (Exception e) { // Driver may not support pExpire or we may be running on Redis 2.4 return connection.expire(rawKey, TimeoutUtils.toSeconds(timeout, unit)); } }, true); }