Skip to content

DATAREDIS-1081 - Fix NPE in Reactive Hash commands #516

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import org.reactivestreams.Publisher;
import org.springframework.dao.InvalidDataAccessApiUsageException;
Expand Down Expand Up @@ -162,7 +163,9 @@ default Mono<Boolean> hSet(ByteBuffer key, ByteBuffer field, ByteBuffer value) {
Assert.notNull(field, "Field must not be null!");
Assert.notNull(value, "Value must not be null!");

return hSet(Mono.just(HSetCommand.value(value).ofField(field).forKey(key))).next().map(BooleanResponse::getOutput);
return hSet(Mono.just(HSetCommand.value(value).ofField(field).forKey(key)))
.next()
.flatMap(response->Mono.justOrEmpty(response.getOutput()));
}

/**
Expand All @@ -180,8 +183,9 @@ default Mono<Boolean> hSetNX(ByteBuffer key, ByteBuffer field, ByteBuffer value)
Assert.notNull(field, "Field must not be null!");
Assert.notNull(value, "Value must not be null!");

return hSet(Mono.just(HSetCommand.value(value).ofField(field).forKey(key).ifValueNotExists())).next()
.map(BooleanResponse::getOutput);
return hSet(Mono.just(HSetCommand.value(value).ofField(field).forKey(key).ifValueNotExists()))
.next()
.flatMap(response->Mono.justOrEmpty(response.getOutput()));
}

/**
Expand Down Expand Up @@ -282,7 +286,7 @@ public List<ByteBuffer> getFields() {
* @see <a href="https://redis.io/commands/hget">Redis Documentation: HGET</a>
*/
default Mono<ByteBuffer> hGet(ByteBuffer key, ByteBuffer field) {
return hMGet(key, Collections.singletonList(field)).map(val -> val.isEmpty() ? null : val.iterator().next());
return hMGet(key, Collections.singletonList(field)).flatMapIterable(Function.identity()).next();
}

/**
Expand All @@ -298,7 +302,9 @@ default Mono<List<ByteBuffer>> hMGet(ByteBuffer key, Collection<ByteBuffer> fiel
Assert.notNull(key, "Key must not be null!");
Assert.notNull(fields, "Fields must not be null!");

return hMGet(Mono.just(HGetCommand.fields(fields).from(key))).next().map(MultiValueResponse::getOutput);
return hMGet(Mono.just(HGetCommand.fields(fields).from(key)))
.next()
.flatMap(res->Mono.justOrEmpty(res.getOutput()));
}

/**
Expand Down Expand Up @@ -374,7 +380,9 @@ default Mono<Boolean> hExists(ByteBuffer key, ByteBuffer field) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(field, "Field must not be null!");

return hExists(Mono.just(HExistsCommand.field(field).in(key))).next().map(BooleanResponse::getOutput);
return hExists(Mono.just(HExistsCommand.field(field).in(key)))
.next()
.flatMap(response->Mono.justOrEmpty(response.getOutput()));
}

/**
Expand Down Expand Up @@ -476,7 +484,9 @@ default Mono<Long> hDel(ByteBuffer key, Collection<ByteBuffer> fields) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(fields, "Fields must not be null!");

return hDel(Mono.just(HDelCommand.fields(fields).from(key))).next().map(NumericResponse::getOutput);
return hDel(Mono.just(HDelCommand.fields(fields).from(key)))
.next()
.flatMap(response->Mono.justOrEmpty(response.getOutput()));
}

/**
Expand All @@ -499,7 +509,9 @@ default Mono<Long> hLen(ByteBuffer key) {

Assert.notNull(key, "Key must not be null!");

return hLen(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput);
return hLen(Mono.just(new KeyCommand(key)))
.next()
.flatMap(response->Mono.justOrEmpty(response.getOutput()));
}

/**
Expand All @@ -522,7 +534,8 @@ default Flux<ByteBuffer> hKeys(ByteBuffer key) {

Assert.notNull(key, "Key must not be null!");

return hKeys(Mono.just(new KeyCommand(key))).flatMap(CommandResponse::getOutput);
return hKeys(Mono.just(new KeyCommand(key)))
.flatMap(CommandResponse::getOutput);
}

/**
Expand Down