在redis中获取lua中的当前日期和时间 [英] get current date and time in lua in redis

查看:2106
本文介绍了在redis中获取lua中的当前日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Redis中嵌入的Lua中的当前日期/时间?

How can I get current date / time in Lua embedded in Redis?

我需要采用以下格式-YYYY-MM-DD,HH:MM:SS

I need to have it in following format - YYYY-MM-DD, HH:MM:SS

尝试使用os.date(),但无法识别它.

Tried with os.date() but it does not recognize it.

推荐答案

Redis'Lua沙箱只有少数几个库,而os不是其中之一.

Redis' Lua sandbox has only a handful of libraries, and os isn't one of these.

您可以像这样从Lua调用Redis TIME :

You can call the Redis TIME from Lua like so:

local t = redis.call('TIME')

但是,您将需要找到一种方法来将纪元转换为所需的格式,并且还要注意,它将阻止脚本执行任何写操作(因为这是不确定的命令).

However, you'll need to find a way to convert the epoch to the desired format and also note that it will stop you script from performing any writes (as it is a non-deterministic command).

更新:从Redis v3.2开始,存在基于效果(而不是基于代码)的脚本的新复制模式.使用此模式时,您实际上可以调用所有随机的,不确定的命令.有关更多信息,请访问 EVAL的文档页面

Update: as of Redis v3.2, there is a new replication mode for scripts that is effect-based (rather than code-based). When using this mode you can actually call all the random, non-deterministic commands. More information is at EVAL's documentation page

这篇关于在redis中获取lua中的当前日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆