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); } }) ); }