@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 Boolean hSetNX(byte[] key, byte[] field, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(field, "Field must not be null!"); Assert.notNull(value, "Value must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().hsetnx(key, field, value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean hSet(byte[] key, byte[] field, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(field, "Field must not be null!"); Assert.notNull(value, "Value must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().hset(key, field, value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean setNX(byte[] key, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().setnx(key, value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean zAdd(byte[] key, double score, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); try { return JedisConverters.toBoolean(connection.getCluster().zadd(key, score, value)); } 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 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 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 Boolean mSetNX(Map<byte[], byte[]> tuples) { Assert.notNull(tuples, "Tuples must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(tuples.keySet().toArray(new byte[tuples.keySet().size()][]))) { try { return JedisConverters.toBoolean(connection.getCluster().msetnx(JedisConverters.toByteArrays(tuples))); } catch (Exception ex) { throw convertJedisAccessException(ex); } } boolean result = true; for (Map.Entry<byte[], byte[]> entry : tuples.entrySet()) { if (!setNX(entry.getKey(), entry.getValue()) && result) { result = false; } } return result; }
@Override public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { Assert.notNull(srcKey, "Source key must not be null!"); Assert.notNull(destKey, "Destination key must not be null!"); Assert.notNull(value, "Value must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(srcKey, destKey)) { try { return JedisConverters.toBoolean(connection.getCluster().smove(srcKey, destKey, value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } } if (connection.keyCommands().exists(srcKey)) { if (sRem(srcKey, value) > 0 && !sIsMember(destKey, value)) { return JedisConverters.toBoolean(sAdd(destKey, value)); } } return Boolean.FALSE; }
@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 Boolean setNX(byte[] key, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().setnx(key, value), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().setnx(key, value), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().setnx(key, value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean zAdd(byte[] key, double score, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().zadd(key, score, value), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().zadd(key, score, value), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().zadd(key, score, value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean pExpire(byte[] key, long millis) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().pexpire(key, millis), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().pexpire(key, millis), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().pexpire(key, millis)); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } }
@Override public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().pexpireAt(key, unixTimeInMillis), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().pexpireAt(key, unixTimeInMillis), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().pexpireAt(key, unixTimeInMillis)); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } }
@Override public Boolean move(byte[] key, int dbIndex) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().move(key, dbIndex), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().move(key, dbIndex), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().move(key, dbIndex)); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } }
@Override public Boolean expireAt(byte[] key, long unixTime) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().expireAt(key, unixTime), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().expireAt(key, unixTime), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().expireAt(key, unixTime)); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } }
@Override public Boolean persist(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline( connection.newJedisResult(connection.getRequiredPipeline().persist(key), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().persist(key), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().persist(key)); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } }
@Override public Boolean mSetNX(Map<byte[], byte[]> tuples) { Assert.notNull(tuples, "Tuples must not be null!"); try { if (isPipelined()) { pipeline( connection.newJedisResult(connection.getRequiredPipeline().msetnx(JedisConverters.toByteArrays(tuples)), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { transaction( connection.newJedisResult(connection.getRequiredTransaction().msetnx(JedisConverters.toByteArrays(tuples)), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(connection.getJedis().msetnx(JedisConverters.toByteArrays(tuples))); } catch (Exception ex) { throw convertJedisAccessException(ex); } }