V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
77yf77yf77yf
V2EX  ›  Java

反应式 redis 流程问题

  •  
  •   77yf77yf77yf · 2021-11-27 18:32:17 +08:00 · 1617 次点击
    这是一个创建于 852 天前的主题,其中的信息可能已经有所发展或是发生改变。
    return valueOperations.set(regCodeKey, regCode, Duration.of(10, TimeUnit.MINUTES.toChronoUnit()))
    .then(reactiveRedisTemplate.hasKey(regCodeObtainRecordKey)
    .doOnSuccess(r ->
    listOperations.leftPush(regCodeObtainRecordKey, current).doOnSuccess(x -> {
    if (!r) {
    reactiveRedisTemplate.expire(regCodeObtainRecordKey, Duration.of(30, TimeUnit.DAYS.toChronoUnit())).subscribe();
    }
    }).subscribe()
    ))
    .doOnSuccess(r -> EmailMessageType.REGISTER.send(Lists.newArrayList(email), Lists.newArrayList(regCode)))
    .map(r -> {
    if (r) {
    return GsonUtil.getGson().toJson(ResponseVO.ResponseCodeMsgMapping.SENDREG_SUCC.getResponse());
    } else {
    return GsonUtil.getGson().toJson(ResponseVO.ResponseCodeMsgMapping.SYS_ERROR.getResponse());
    }
    });

    11 行的 doOnSuccess 能否在第二行 then 中的操作完全做完才进行(我感觉应该不太行)
    如果不行应该怎么改
    5 条回复    2021-11-28 09:58:47 +08:00
    yidinghe
        1
    yidinghe  
       2021-11-27 19:29:18 +08:00 via Android
    建议代码粘贴到 github ,然后在这里贴链接
    77yf77yf77yf
        2
    77yf77yf77yf  
    OP
       2021-11-27 19:42:26 +08:00
    return valueOperations.set(regCodeKey, regCode, Duration.of(10, TimeUnit.MINUTES.toChronoUnit()))
    .then(reactiveRedisTemplate.hasKey(regCodeObtainRecordKey)
    .doOnSuccess(hasRecordKey ->
    listOperations.leftPush(regCodeObtainRecordKey, current).doOnSuccess(x -> {
    if (!hasRecordKey) {
    reactiveRedisTemplate.expire(regCodeObtainRecordKey, Duration.of(30, TimeUnit.DAYS.toChronoUnit()))
    .doOnSuccess(opeSucc -> {
    if (opeSucc) {
    EmailMessageType.REGISTER.send(Lists.newArrayList(email), Lists.newArrayList(regCode));
    }
    }).subscribe();
    }
    }).subscribe()
    ))
    .map(r -> {
    if (r) {
    return ResponseVO.ResponseCodeMsgMapping.SENDREG_SUCC.getResponse().toJson();
    } else {
    return ResponseVO.ResponseCodeMsgMapping.SYS_ERROR.getResponse().toJson();
    }
    });

    想了想改了之后是这样的
    但是还是有个问题,最后我要将整个流程完成与否的结果转化为 Mono<String>,但是如果像这样在最后 map 的话应该只是对 hasKey 的结果进行转化,有没有什么办法以最后整个流程完成的结果来转化
    77yf77yf77yf
        3
    77yf77yf77yf  
    OP
       2021-11-27 19:43:09 +08:00
    77yf77yf77yf
        4
    77yf77yf77yf  
    OP
       2021-11-27 19:45:27 +08:00
    @yidinghe 已贴到 github ,有空希望再看一下,谢谢
    jalena
        5
    jalena  
       2021-11-28 09:58:47 +08:00
    ` ```java `这样贴不好吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   941 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:32 · PVG 05:32 · LAX 14:32 · JFK 17:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.