List of usage examples for org.springframework.data.redis.connection RedisConnection pSetEx
@Nullable Boolean pSetEx(byte[] key, long milliseconds, byte[] value);
From source file:com.mauersu.util.redis.DefaultValueOperations.java
public void set(K key, V value, final long timeout, final TimeUnit unit) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); execute(new RedisCallback<Object>() { public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.select(dbIndex);// ww w .j a v a 2s . c o m potentiallyUsePsetEx(connection); return null; } public void potentiallyUsePsetEx(RedisConnection connection) { if (!TimeUnit.MILLISECONDS.equals(unit) || !failsafeInvokePsetEx(connection)) { connection.select(dbIndex); connection.setEx(rawKey, TimeoutUtils.toSeconds(timeout, unit), rawValue); } } private boolean failsafeInvokePsetEx(RedisConnection connection) { boolean failed = false; try { connection.select(dbIndex); connection.pSetEx(rawKey, timeout, rawValue); } catch (UnsupportedOperationException e) { // in case the connection does not support pSetEx return false to allow fallback to other operation. failed = true; } return !failed; } }, true); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Set the {@code value} and expiration in {@code milliseconds} for {@code key}. * <p>//w w w . j a v a 2 s . co m * See http://redis.io/commands/psetex * * @param key must not be {@literal null}. * @param milliseconds exprise milliseconds * @param value must not be {@literal null}. * @since 1.3 */ public static void pSetEx(byte[] key, long milliseconds, byte[] value) { redisTemplate.execute(new RedisCallback<Void>() { @Override public Void doInRedis(RedisConnection redis) throws DataAccessException { redis.pSetEx(key, milliseconds, value); return null; } }); }
From source file:com.zxy.commons.cache.RedisHelper.java
/** * Set the {@code value} and expiration in {@code milliseconds} for {@code key}. * <p>/* w ww. j a va 2s . c om*/ * See http://redis.io/commands/psetex * * @param key must not be {@literal null}. * @param milliseconds exprise milliseconds * @param value must not be {@literal null}. * @since 1.3 */ public void pSetEx(byte[] key, long milliseconds, byte[] value) { redisTemplate.execute(new RedisCallback<Void>() { @Override public Void doInRedis(RedisConnection redis) throws DataAccessException { redis.pSetEx(key, milliseconds, value); return null; } }); }