英文:
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的结果生成的。
关于这一点,有两种可能的实现方式。
- 使用带有额外EX参数的SET命令。在这种情况下,您的命令将类似于:
Request.cmd(Command.SET).arg("mykey").arg("myvalue").arg("EX").arg("15")
- 使用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.
- 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")
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论