Get current date and time in lua in redis

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

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

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

+4
source share
1 answer

There are only a few libraries in the Redis Lua sandbox, and os not one of them.

You can call Redis TIME from Lua, for example:

 local t = redis.call('TIME') 

However, you need to find a way to convert the era into the desired format, and also note that it will not allow you to execute a script entry (since this is not a deterministic command).

Update: With Redis v3.2, there is a new replication mode for effect-based scripts (not code-based). When using this mode, you can actually name all random, non-deterministic commands. See the EVAL page for more information.

+10
source

All Articles