Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Project Reactor: is it right to call subscribe within async context?

$
0
0

I stock encryption keys in redis database. I want to implement a fallback mecanism to generate keys unless they are already present.What perturbates me with a solution I come up with is that I call subscribe within an async context. My IDE pointed me this problem. So the question is how would you impelement this fallback?

    public Mono<String> getEncryptionKey(String entity) {        return reactiveRedisOperations.opsForValue()                .get("private")                .switchIfEmpty(                        Mono.create(stringMonoSink -> {                            try {                                var privateKeyEncoded = ...                                var publicKeyEncoded = ...                                reactiveRedisOperations.opsForValue()                                        .multiSet(Map.of("private", privateKeyEncoded,"public", publicKeyEncoded                                        ))                                        .subscribe(success -> {                                            stringMonoSink.success(privateKeyEncoded);                                        });                            } catch (Throwable e) {                                stringMonoSink.error(e);                            }                        })                );    }

Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>