@Override public Boolean expire(byte[] key, long seconds) { Assert.notNull(key, "Key must not be null!"); if (seconds > Integer.MAX_VALUE) { throw new UnsupportedOperationException("Jedis does not support seconds exceeding Integer.MAX_VALUE."); } try { return JedisConverters.toBoolean(connection.getCluster().expire(key, Long.valueOf(seconds).intValue())); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long ttl(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().ttl(key); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().pexpireAt(key, unixTimeInMillis)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long ttl(byte[] key, TimeUnit timeUnit) { Assert.notNull(key, "Key must not be null!"); try { return Converters.secondsToTimeUnit(connection.getCluster().ttl(key), timeUnit); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean pExpire(byte[] key, long millis) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().pexpire(key, millis)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean persist(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().persist(key)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public DataType type(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toDataType(connection.getCluster().type(key)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean expireAt(byte[] key, long unixTime) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().expireAt(key, unixTime)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public List<byte[]> sort(byte[] key, SortParameters params) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().sort(key, JedisConverters.toSortingParams(params)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Nullable @Override public Long exists(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); Assert.noNullElements(keys, "Keys must not contain null elements!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { try { return connection.getCluster().exists(keys); } catch (Exception ex) { throw convertJedisAccessException(ex); } } return connection.getClusterCommandExecutor() .executeMultiKeyCommand((JedisMultiKeyClusterCommandCallback<Boolean>) BinaryJedis::exists, Arrays.asList(keys)) .resultsAsList().stream().mapToLong(val -> ObjectUtils.nullSafeEquals(val, Boolean.TRUE) ? 1 : 0).sum(); }
@Override public Long del(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); Assert.noNullElements(keys, "Keys must not contain null elements!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { try { return connection.getCluster().del(keys); } catch (Exception ex) { throw convertJedisAccessException(ex); } } return (long) connection.getClusterCommandExecutor() .executeMultiKeyCommand((JedisMultiKeyClusterCommandCallback<Long>) (client, key) -> client.del(key), Arrays.asList(keys)) .resultsAsList().size(); }
@Override public void rename(byte[] sourceKey, byte[] targetKey) { Assert.notNull(sourceKey, "Source key must not be null!"); Assert.notNull(targetKey, "Target key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) { try { connection.getCluster().rename(sourceKey, targetKey); return; } catch (Exception ex) { throw convertJedisAccessException(ex); } } byte[] value = dump(sourceKey); if (value != null && value.length > 0) { restore(targetKey, 0, value); del(sourceKey); } }
@Override public Boolean renameNX(byte[] sourceKey, byte[] targetKey) { Assert.notNull(sourceKey, "Source key must not be null!"); Assert.notNull(targetKey, "Target key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) { try { return JedisConverters.toBoolean(connection.getCluster().renamenx(sourceKey, targetKey)); } catch (Exception ex) { throw convertJedisAccessException(ex); } } byte[] value = dump(sourceKey); if (value != null && value.length > 0 && !exists(targetKey)) { restore(targetKey, 0, value); del(sourceKey); return Boolean.TRUE; } return Boolean.FALSE; }
@Override public Long ttl(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().ttl(key); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().pexpireAt(key, unixTimeInMillis)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().pexpireAt(key, unixTimeInMillis)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean persist(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().persist(key)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long ttl(byte[] key, TimeUnit timeUnit) { Assert.notNull(key, "Key must not be null!"); try { return Converters.secondsToTimeUnit(connection.getCluster().ttl(key), timeUnit); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public List<byte[]> sort(byte[] key, SortParameters params) { Assert.notNull(key, "Key must not be null!"); try { return connection.getCluster().sort(key, JedisConverters.toSortingParams(params)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long ttl(byte[] key, TimeUnit timeUnit) { Assert.notNull(key, "Key must not be null!"); try { return Converters.secondsToTimeUnit(connection.getCluster().ttl(key), timeUnit); } catch (Exception ex) { throw convertJedisAccessException(ex); } }