spring-projects / spring-data-redis

Provides support to increase developer productivity in Java when using Redis, a key-value store. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-redis/
Apache License 2.0
1.77k stars 1.17k forks source link

DefaultReactiveHashOperations$$Lambda$1949/0x0000000801666b30] returned a null value. #3031

Closed wang-sheng-pu1002 closed 2 weeks ago

wang-sheng-pu1002 commented 4 weeks ago

The mapper [org.springframework.data.redis.core.DefaultReactiveHashOperations$$Lambda$1949/0x0000000801666b30] returned a null value. java.lang.NullPointerException: The mapper [org.springframework.data.redis.core.DefaultReactiveHashOperations$$Lambda$1949/0x0000000801666b30] returned a null value. at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:108) Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:

The above is my error message

My partial code

private Mono<Boolean> getExpertSystemFlag(String key) {
    return reactiveRedisTemplate.opsForHash().get(key, "sessionAttr:AAA")
            .flatMap(systemFlag -> {
                return Mono.just(systemFlagList.contains(systemFlag));
            })
            .switchIfEmpty(Mono.defer(() -> {
                return Mono.just(false);
            }));
}

When I confirm the existence of this key primary key in Redis, but there is no sessionAttr: AAA object in it, I occasionally encounter an error

wang-sheng-pu1002 commented 4 weeks ago
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
    <version>3.0.13</version>
  </dependency>
wang-sheng-pu1002 commented 4 weeks ago
@Bean(name = "reactiveRedisTemplate")
public ReactiveRedisTemplate<String, Object> reactiveRedisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
    StringRedisSerializer stringSerializer = new StringRedisSerializer();
    JdkSerializationRedisSerializer jdkSerializer = new JdkSerializationRedisSerializer();
    RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext.<String, Object>newSerializationContext(stringSerializer)
            .key(stringSerializer)
            .hashKey(stringSerializer)
            .value(jdkSerializer)
            .hashValue(jdkSerializer)
            .build();
    return new ReactiveRedisTemplate<>(lettuceConnectionFactory, serializationContext);
}
mp911de commented 4 weeks ago

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Please also note that the version 3.0 (and 3.1) are no longer maintained. Please consider upgrading to 3.2.x or 3.3.x

spring-projects-issues commented 3 weeks ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 2 weeks ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.