Reactive Redis 添加键-值-过期时间

huangapple go评论64阅读模式
英文:

Reactive redis add key-value-expiration

问题

I'm using quarkus, it has a reactive connection to redis. I need to add key-value-expiration. Due to the fact that this is reactive programming, I do not understand how to do this, please help.

there is an example, but it doesn't have an example of adding a key with a value:
https://quarkus.io/guides/redis#creating-the-increment-service

ReactiveKeyCommands does not have an add, set, setex methods.

英文:

I'm using quarkus, it has a reactive connection to redis. I need to add key-value-expiration. Due to the fact that this is reactive programming, I do not understand how to do this, please help.

there is an example, but it doesn't have an example of adding a key with a value:
https://quarkus.io/guides/redis#creating-the-increment-service

ReactiveKeyCommands<String> does not have an add, set, setex methods.

答案1

得分: 0

private final ReactiveValueCommands&lt;String, String&gt; valueCommands;

public ConstructorMyBean(ReactiveRedisDataSource reactive) {
    this.valueCommands = reactive.value(String.class, String.class);
}

valueCommands.setex(&quot;key&quot;, 90000, &quot;value&quot;)
   .subscribeAsCompletionStage().thenApply(status-&gt; &quot;成功&quot;);
英文:
private final ReactiveValueCommands&lt;String, String&gt; valueCommands;

public ConstructorMyBean(ReactiveRedisDataSource reactive) {
        this.valueCommands = reactive.value(String.class, String.class);
}

valueCommands.setex(&quot;key&quot;, 90000, &quot;value&quot;)
   .subscribeAsCompletionStage().thenApply(status-&gt; &quot;Successfully&quot;);

how stupid I am, but to be honest, before I asked, nothing worked

huangapple
  • 本文由 发表于 2023年5月20日 22:39:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76295769.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定