@Override public Properties info(String section) { Assert.hasText(section, "Section must not be null or empty!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().info(section), LettuceConverters.stringToProps())); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().info(section), LettuceConverters.stringToProps())); return null; } return LettuceConverters.toProperties(getConnection().info(section)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
/** * Converts a given {@link Boundary} to its binary representation suitable for ZRANGEBYLEX command. * * @param boundary * @return * @since 1.6 */ public static String boundaryToBytesForZRangeByLex(Boundary boundary, byte[] defaultValue) { if (boundary == null || boundary.getValue() == null) { return toString(defaultValue); } return boundaryToBytes(boundary, toBytes("["), toBytes("(")); }
public static String boundaryToStringForZRange(Boundary boundary, String defaultValue) { if (boundary == null || boundary.getValue() == null) { return defaultValue; } return boundaryToString(boundary, "", "("); }
@Override public Set<byte[]> zRevRange(byte[] key, long start, long end) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().zrevrange(key, start, end), LettuceConverters.bytesListToBytesSet())); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().zrevrange(key, start, end), LettuceConverters.bytesListToBytesSet())); return null; } return LettuceConverters.toBytesSet(getConnection().zrevrange(key, start, end)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public List<Object> exec() { isMulti = false; try { if (isPipelined()) { RedisFuture<TransactionResult> exec = getAsyncDedicatedRedisCommands().exec(); LettuceTransactionResultConverter resultConverter = new LettuceTransactionResultConverter( new LinkedList<>(txResults), LettuceConverters.exceptionConverter()); pipeline(newLettuceResult(exec, source -> resultConverter .convert(LettuceConverters.transactionResultUnwrapper().convert((TransactionResult) source)))); return null; } TransactionResult transactionResult = (getDedicatedRedisCommands()).exec(); List<Object> results = LettuceConverters.transactionResultUnwrapper().convert(transactionResult); return convertPipelineAndTxResults ? new LettuceTransactionResultConverter(txResults, LettuceConverters.exceptionConverter()).convert(results) : results; } catch (Exception ex) { throw convertLettuceAccessException(ex); } finally { txResults.clear(); } }
@Override public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(member, "Member must not be null!"); Assert.notNull(radius, "Radius must not be null!"); GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(radius.getMetric()); Converter<Set<byte[]>, GeoResults<GeoLocation<byte[]>>> converter = LettuceConverters .bytesSetToGeoResultsConverter(); try { if (isPipelined()) { pipeline(connection.newLettuceResult( getAsyncConnection().georadiusbymember(key, member, radius.getValue(), geoUnit), converter)); return null; } if (isQueueing()) { transaction(connection.newLettuceResult( getAsyncConnection().georadiusbymember(key, member, radius.getValue(), geoUnit), converter)); return null; } return converter.convert(getConnection().georadiusbymember(key, member, radius.getValue(), geoUnit)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Set<byte[]> hKeys(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().hkeys(key), LettuceConverters.bytesListToBytesSet())); return null; } if (isQueueing()) { transaction( connection.newLettuceResult(getAsyncConnection().hkeys(key), LettuceConverters.bytesListToBytesSet())); return null; } return LettuceConverters.toBytesSet(getConnection().hkeys(key)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Flux<CommandResponse<GeoDistCommand, Distance>> geoDist(Publisher<GeoDistCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getFrom(), "From member must not be null!"); Assert.notNull(command.getTo(), "To member must not be null!"); Metric metric = command.getMetric().isPresent() ? command.getMetric().get() : RedisGeoCommands.DistanceUnit.METERS; GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(metric); Converter<Double, Distance> distanceConverter = LettuceConverters.distanceConverterForMetric(metric); Mono<Distance> result = cmd.geodist(command.getKey(), command.getFrom(), command.getTo(), geoUnit) .map(distanceConverter::convert); return result.map(value -> new CommandResponse<>(command, value)); })); }
@Override public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(member1, "Member1 must not be null!"); Assert.notNull(member2, "Member2 must not be null!"); Assert.notNull(metric, "Metric must not be null!"); GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(metric); Converter<Double, Distance> distanceConverter = LettuceConverters.distanceConverterForMetric(metric); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit), distanceConverter)); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit), distanceConverter)); return null; } return distanceConverter.convert(getConnection().geodist(key, member1, member2, geoUnit)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
<T> Function<Throwable, Throwable> translateException() { return throwable -> { if (throwable instanceof RuntimeException) { DataAccessException convertedException = LettuceConverters.exceptionConverter() .convert((RuntimeException) throwable); return convertedException != null ? convertedException : throwable; } return throwable; }; }
String redisVersion = LettuceConverters.stringToProps().convert(infoServer).getProperty("redis_version"); Version runningVersion = Version.parse(redisVersion);
@Override public Properties info() { try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().info(), LettuceConverters.stringToProps())); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().info(), LettuceConverters.stringToProps())); return null; } return LettuceConverters.toProperties(getConnection().info()); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Long lastSave() { try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().lastsave(), LettuceConverters.dateToLong())); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().lastsave(), LettuceConverters.dateToLong())); return null; } return LettuceConverters.toLong(getConnection().lastsave()); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public String getClientName() { try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().clientGetname(), LettuceConverters.bytesToString())); return null; } if (isQueueing()) { transaction( connection.newLettuceResult(getAsyncConnection().clientGetname(), LettuceConverters.bytesToString())); return null; } return LettuceConverters.toString(getConnection().clientGetname()); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
private Converter<GeoWithin<ByteBuffer>, GeoResult<GeoLocation<ByteBuffer>>> converter(Metric metric) { return (source) -> { Point point = LettuceConverters.geoCoordinatesToPoint(source.getCoordinates()); return new GeoResult<>(new GeoLocation<>(source.getMember(), point), new Distance(source.getDistance() != null ? source.getDistance() : 0D, metric)); }; } }
@Override public Set<byte[]> zRangeByScore(byte[] key, String min, String max) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().zrangebyscore(key, min, max), LettuceConverters.bytesListToBytesSet())); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().zrangebyscore(key, min, max), LettuceConverters.bytesListToBytesSet())); return null; } return LettuceConverters.toBytesSet(getConnection().zrangebyscore(key, min, max)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(within, "Within must not be null!"); Converter<Set<byte[]>, GeoResults<GeoLocation<byte[]>>> geoResultsConverter = LettuceConverters .bytesSetToGeoResultsConverter(); try { if (isPipelined()) { pipeline(connection.newLettuceResult( getAsyncConnection().georadius(key, within.getCenter().getX(), within.getCenter().getY(), within.getRadius().getValue(), LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric())), geoResultsConverter)); return null; } if (isQueueing()) { transaction(connection.newLettuceResult( getAsyncConnection().georadius(key, within.getCenter().getX(), within.getCenter().getY(), within.getRadius().getValue(), LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric())), geoResultsConverter)); return null; } return geoResultsConverter .convert(getConnection().georadius(key, within.getCenter().getX(), within.getCenter().getY(), within.getRadius().getValue(), LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric()))); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Set<byte[]> keys(byte[] pattern) { Assert.notNull(pattern, "Pattern must not be null!"); try { if (isPipelined()) { pipeline( connection.newLettuceResult(getAsyncConnection().keys(pattern), LettuceConverters.bytesListToBytesSet())); return null; } if (isQueueing()) { transaction( connection.newLettuceResult(getAsyncConnection().keys(pattern), LettuceConverters.bytesListToBytesSet())); return null; } return LettuceConverters.toBytesSet(getConnection().keys(pattern)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Flux<CommandResponse<GeoDistCommand, Distance>> geoDist(Publisher<GeoDistCommand> commands) { return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getFrom(), "From member must not be null!"); Assert.notNull(command.getTo(), "To member must not be null!"); Metric metric = command.getMetric().isPresent() ? command.getMetric().get() : RedisGeoCommands.DistanceUnit.METERS; GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(metric); Converter<Double, Distance> distanceConverter = LettuceConverters.distanceConverterForMetric(metric); Mono<Distance> result = cmd.geodist(command.getKey(), command.getFrom(), command.getTo(), geoUnit) .map(distanceConverter::convert); return result.map(value -> new CommandResponse<>(command, value)); })); }
@Override public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(member1, "Member1 must not be null!"); Assert.notNull(member2, "Member2 must not be null!"); Assert.notNull(metric, "Metric must not be null!"); GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(metric); Converter<Double, Distance> distanceConverter = LettuceConverters.distanceConverterForMetric(metric); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit), distanceConverter)); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit), distanceConverter)); return null; } return distanceConverter.convert(getConnection().geodist(key, member1, member2, geoUnit)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }