@Override public Properties getConfig(RedisClusterNode node, String pattern) { Assert.notNull(pattern, "Pattern must not be null!"); return connection.getClusterCommandExecutor() .executeCommandOnSingleNode( (JedisClusterCommandCallback<Properties>) client -> Converters.toProperties(client.configGet(pattern)), node) .getValue(); }
/** * Constructs a new <code>DefaultStringRedisConnection</code> instance. * * @param connection Redis connection * @param serializer String serializer */ public DefaultStringRedisConnection(RedisConnection connection, RedisSerializer<String> serializer) { Assert.notNull(connection, "connection is required"); Assert.notNull(serializer, "serializer is required"); this.delegate = connection; this.serializer = serializer; this.byteGeoResultsToStringGeoResults = Converters.deserializingGeoResultsConverter(serializer); }
@Override public Properties getConfig(String pattern) { Assert.notNull(pattern, "Pattern must not be null!"); try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().configGet(pattern), Converters.listToPropertiesConverter())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().configGet(pattern), Converters.listToPropertiesConverter())); return null; } return Converters.toProperties(connection.getJedis().configGet(pattern)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean set(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().set(key, value), Converters.stringToBooleanConverter())); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().set(key, value), Converters.stringToBooleanConverter())); return null; } return Converters.stringToBoolean(connection.getJedis().set(key, value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean pSetEx(byte[] key, long milliseconds, 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().psetex(key, milliseconds, value), Converters.stringToBooleanConverter(), () -> false)); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().psetex(key, milliseconds, value), Converters.stringToBooleanConverter(), () -> false)); return null; } return Converters.stringToBoolean(connection.getJedis().psetex(key, milliseconds, value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean setEx(byte[] key, long seconds, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); if (seconds > Integer.MAX_VALUE) { throw new IllegalArgumentException("Time must be less than Integer.MAX_VALUE for setEx in Jedis."); } try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().setex(key, (int) seconds, value), Converters.stringToBooleanConverter(), () -> false)); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().setex(key, (int) seconds, value), Converters.stringToBooleanConverter(), () -> false)); return null; } return Converters.stringToBoolean(connection.getJedis().setex(key, (int) seconds, value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean setEx(byte[] key, long seconds, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().setex(key, seconds, value), Converters.stringToBooleanConverter())); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().setex(key, seconds, value), Converters.stringToBooleanConverter())); return null; } return Converters.stringToBoolean(getConnection().setex(key, seconds, value)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Boolean setEx(byte[] key, long seconds, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); if (seconds > Integer.MAX_VALUE) { throw new IllegalArgumentException("Seconds have cannot exceed Integer.MAX_VALUE!"); } try { return Converters.stringToBoolean(connection.getCluster().setex(key, Long.valueOf(seconds).intValue(), value)); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Long pTtl(byte[] key, TimeUnit timeUnit) { Assert.notNull(key, "Key must not be null!"); return connection.getClusterCommandExecutor() .executeCommandOnSingleNode( (JedisClusterCommandCallback<Long>) client -> Converters.millisecondsToTimeUnit(client.pttl(key), timeUnit), connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key)) .getValue(); }
@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 Long ttl(byte[] key, TimeUnit timeUnit) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().ttl(key), Converters.secondsToTimeUnit(timeUnit))); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().ttl(key), Converters.secondsToTimeUnit(timeUnit))); return null; } return Converters.secondsToTimeUnit(connection.getJedis().ttl(key), timeUnit); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } }
@Override public Boolean mSet(Map<byte[], byte[]> tuples) { Assert.notNull(tuples, "Tuples must not be null!"); try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().mset(JedisConverters.toByteArrays(tuples)), Converters.stringToBooleanConverter())); return null; } if (isQueueing()) { transaction( connection.newJedisResult(connection.getRequiredTransaction().mset(JedisConverters.toByteArrays(tuples)), Converters.stringToBooleanConverter())); return null; } return Converters.stringToBoolean(connection.getJedis().mset(JedisConverters.toByteArrays(tuples))); } catch (Exception ex) { throw convertJedisAccessException(ex); } }
@Override public Boolean pSetEx(byte[] key, long milliseconds, byte[] value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); return Converters.stringToBoolean(connection.getClusterCommandExecutor() .executeCommandOnSingleNode( (JedisClusterCommandCallback<String>) client -> client.psetex(key, milliseconds, value), connection.getTopologyProvider().getTopology().getKeyServingMasterNode(key)) .getValue()); }
@Nullable @Override public Duration idletime(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newJedisResult(connection.getRequiredPipeline().objectIdletime(key), Converters::secondsToDuration)); return null; } if (isQueueing()) { transaction(connection.newJedisResult(connection.getRequiredTransaction().objectIdletime(key), Converters::secondsToDuration)); return null; } return Converters.secondsToDuration(connection.getJedis().objectIdletime(key)); } catch (Exception ex) { throw connection.convertJedisAccessException(ex); } }
@Nullable @Override public Duration idletime(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().objectIdletime(key), Converters::secondsToDuration)); return null; } if (isQueueing()) { transaction( connection.newLettuceResult(getAsyncConnection().objectIdletime(key), Converters::secondsToDuration)); return null; } return Converters.secondsToDuration(getConnection().objectIdletime(key)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Long pTtl(byte[] key, TimeUnit timeUnit) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline( connection.newLettuceResult(getAsyncConnection().pttl(key), Converters.millisecondsToTimeUnit(timeUnit))); return null; } if (isQueueing()) { transaction( connection.newLettuceResult(getAsyncConnection().pttl(key), Converters.millisecondsToTimeUnit(timeUnit))); return null; } return Converters.millisecondsToTimeUnit(getConnection().pttl(key), timeUnit); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Properties getConfig(String pattern) { Assert.hasText(pattern, "Pattern must not be null or empty!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().configGet(pattern), Converters.mapToPropertiesConverter())); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().configGet(pattern), Converters.mapToPropertiesConverter())); return null; } return Converters.toProperties(getConnection().configGet(pattern)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Properties getConfig(RedisClusterNode node, String pattern) { Assert.hasText(pattern, "Pattern must not be null or empty!"); return executeCommandOnSingleNode(client -> Converters.toProperties(client.configGet(pattern)), node).getValue(); }
private static List<RedisServer> toRedisServersList(List<Map<String, String>> source) { List<RedisServer> servers = new ArrayList<RedisServer>(source.size()); for (Map<String, String> info : source) { servers.add(RedisServer.newServerFrom(Converters.toProperties(info))); } return servers; }
/** * Creates a new {@link Converter} to convert from seconds to the given {@link TimeUnit}. * * @param timeUnit muist not be {@literal null}. * @return * @since 1.8 */ public static Converter<Long, Long> secondsToTimeUnit(final TimeUnit timeUnit) { return seconds -> secondsToTimeUnit(seconds, timeUnit); }