Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Jedis 5.0 #2716

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Refactor and fix compiler warnings in FutureResult and JedisResult.
  • Loading branch information
jxblum committed Sep 25, 2023
commit 3558c916a849de8b4d94d61bc1800398fdce2402
Original file line number Diff line number Diff line change
@@ -21,22 +21,25 @@
import org.springframework.lang.Nullable;

/**
* The result of an asynchronous operation
* Result of an asynchronous operation
*
* @param <T> The data type of the object that holds the future result (usually type of the
* {@link java.util.concurrent.Future} or response wrapper).
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Mark Paluch
* @param <T> The data type of the object that holds the future result (usually type of the
* {@link java.util.concurrent.Future} or response wrapper).
* @author John Blum
*/
public abstract class FutureResult<T> {

private T resultHolder;
private boolean status = false;

private final T resultHolder;

private final Supplier<?> defaultConversionResult;

private boolean status = false;

@SuppressWarnings("rawtypes") //
@SuppressWarnings("rawtypes")
protected Converter converter;

/**
@@ -71,23 +74,14 @@ public FutureResult(T resultHolder, @Nullable Converter converter) {
* @param defaultConversionResult must not be {@literal null}.
* @since 2.1
*/
@SuppressWarnings("rawtypes")
public FutureResult(T resultHolder, @Nullable Converter converter, Supplier<?> defaultConversionResult) {

this.resultHolder = resultHolder;
this.converter = converter != null ? converter : val -> val;
this.defaultConversionResult = defaultConversionResult;
}

/**
* Get the object holding the actual result.
*
* @return never {@literal null}.
* @since 1.1
*/
public T getResultHolder() {
return resultHolder;
}

/**
* Converts the given result if a converter is specified, else returns the result
*
@@ -98,11 +92,9 @@ public T getResultHolder() {
@Nullable
public Object convert(@Nullable Object result) {

if (result == null) {
return computeDefaultResult(null);
}
Object resolvedResult = result != null ? getConverter().convert(result) : null;

return computeDefaultResult(converter.convert(result));
return computeDefaultResult(resolvedResult);
}

@Nullable
@@ -112,7 +104,17 @@ private Object computeDefaultResult(@Nullable Object source) {

@SuppressWarnings("rawtypes")
public Converter getConverter() {
return converter;
return this.converter;
}

/**
* Get the object holding the actual result.
*
* @return never {@literal null}.
* @since 1.1
*/
public T getResultHolder() {
return this.resultHolder;
}

/**
@@ -121,7 +123,7 @@ public Converter getConverter() {
* @return true if this is a status result (i.e. OK)
*/
public boolean isStatus() {
return status;
return this.status;
}

/**
@@ -144,4 +146,5 @@ public void setStatus(boolean status) {
* @since 2.1
*/
public abstract boolean conversionRequired();

}
Original file line number Diff line number Diff line change
@@ -24,24 +24,21 @@
import org.springframework.lang.Nullable;

/**
* Jedis specific {@link FutureResult} implementation. <br />
* {@link FutureResult} implementation for Jedis.
*
* @param <T> The data type of the object that holds the future result (usually of type Future).
* @param <R> The data type of the result type.
* @author Costin Leau
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Mark Paluch
* @param <T> The data type of the object that holds the future result (usually of type Future).
* @param <R> The data type of the result type.
* @author John Blum
* @since 2.1
*/
class JedisResult<T, R> extends FutureResult<Response<?>> {

private final boolean convertPipelineAndTxResults;

JedisResult(Response<T> resultHolder) {
this(resultHolder, false, null);
}

JedisResult(Response<T> resultHolder, boolean convertPipelineAndTxResults, @Nullable Converter<T, ?> converter) {
this(resultHolder, () -> null, convertPipelineAndTxResults, converter);
}
@@ -50,6 +47,7 @@ class JedisResult<T, R> extends FutureResult<Response<?>> {
@Nullable Converter<T, ?> converter) {

super(resultHolder, converter, defaultReturnValue);

this.convertPipelineAndTxResults = convertPipelineAndTxResults;
}

@@ -61,18 +59,18 @@ public T get() {
}

public boolean conversionRequired() {
return convertPipelineAndTxResults;
return this.convertPipelineAndTxResults;
}

/**
* Jedis specific {@link FutureResult} implementation of a throw away status result.
*/
static class JedisStatusResult<T, R> extends JedisResult<T, R> {

@SuppressWarnings("unchecked")
JedisStatusResult(Response<T> resultHolder, Converter<T, R> converter) {

super(resultHolder, false, converter);

setStatus(true);
}
}
@@ -86,9 +84,12 @@ static class JedisStatusResult<T, R> extends JedisResult<T, R> {
*/
static class JedisResultBuilder<T, R> {

private final Response<T> response;
private Converter<T, R> converter;
private boolean convertPipelineAndTxResults = false;

private Converter<T, R> converter;

private final Response<T> response;

private Supplier<R> nullValueDefault = () -> null;

@SuppressWarnings("unchecked")
@@ -119,6 +120,7 @@ static <T, R> JedisResultBuilder<T, R> forResponse(Response<T> response) {
JedisResultBuilder<T, R> mappedWith(Converter<T, R> converter) {

this.converter = converter;

return this;
}

@@ -131,12 +133,14 @@ JedisResultBuilder<T, R> mappedWith(Converter<T, R> converter) {
JedisResultBuilder<T, R> mapNullTo(Supplier<R> supplier) {

this.nullValueDefault = supplier;

return this;
}

JedisResultBuilder<T, R> convertPipelineAndTxResults(boolean flag) {

convertPipelineAndTxResults = flag;
this.convertPipelineAndTxResults = flag;

return this;
}