设置 Redis 命令请求的过期时间。

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

Set Expiration to Redis Command request

问题

如何在Request对象中设置过期时间?

我有以下代码:

Request r = Request.cmd(Command.SET).arg("mykey").arg("myvalue");

如何设置该键的过期时间?我不太理解getDelegate()方法的作用。

我不想再写一个类似这样的Request命令:

Request expire = Request.cmd(Command.EXPIRE).arg("mykey").arg(20);

我希望只使用一个Request对象来完成。

这种做法可行吗?

英文:

How to set the expiration within a Request object?

I have

Request r = Request.cmd(Command.SET).arg("mykey").arg("myvalue");

How to set the expiration of that key? I don't really understand the purpose of the getDelegate() method.

I don't want to write an other Request command like that :

Request expire = Request.cmd(Command.EXPIRE).arg("mykey").arg(20);

I want to do it in only one Request object.

Is it possible ?

答案1

得分: 0

Vert.x Redis客户端API的设计目标是尽可能接近原始的REDIS命令。这是因为Vert.x Redis接口是直接从COMMAND的结果生成的。

关于这一点,有两种可能的实现方式。

  1. 使用带有额外EX参数的SET命令。在这种情况下,您的命令将类似于:
Request.cmd(Command.SET).arg("mykey").arg("myvalue").arg("EX").arg("15")
  1. 使用SETEX命令。在这种情况下,您的命令将类似于:
Request.cmd(Command.SETEX).arg("mykey").arg("15").arg("myvalue")

最佳使用Vert.x Redis客户端API的方法是始终通过REDIS COMMANDS检查每个命令的使用方式,并将其1:1转换为Vert.X API。

英文:

Vert.x Redis Client API idea is to be as close to original REDIS commands as possible. This is because the Vertx.X Redis interfaces are directly generated from result of COMMAND

In regards to this there are 2 possible ways to achieve this.

  1. Using SET command with additional EX parameter. In this case your command will look something like this:
Request.cmd(Command.SET).arg("mykey").arg("myvalue").arg("EX").arg("15")
  1. Using SETEX command. In this case your command will look something like this:
Request.cmd(Command.SETEX).arg("mykey").arg("15").arg("myvalue")

Best way to use Vert.x Redis Client API is to always check how each command is used via REDIS COMMANDS and transfer that 1:1 to Vert.X API.

huangapple
  • 本文由 发表于 2023年7月27日 15:18:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76777317.html
匿名

发表评论

匿名网友

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

确定