Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current time in Redis

Tags:

redis

The time command gives me a list, and I'm not able to get the first element in it using any normal list commands.

redis 127.0.0.1:6379> time

1) "1375802172"

2) "168215"

redis 127.0.0.1:6379> lrange time 0 1

(empty list or set)

like image 401
hugh Avatar asked Oct 04 '22 07:10

hugh


2 Answers

It is completely unrelated to a Redis list type. The fact that a number of list operations return a multi-bulk reply does not mean that all multi-bulk replies are Redis lists.

TIME does return a standard multi-bulk reply containing two values. The first one is the Unix epoch time, and the second the number of microseconds.

If you only need one of these values, it is up to the client program to select it.

like image 188
Didier Spezia Avatar answered Oct 07 '22 17:10

Didier Spezia


The previous answer is correct, TIME does not return a redis list.

However, you might be able to achieve what you are seeking using a lua script:

EVAL "return redis.call('TIME')[1]" 0 0
like image 36
Fabio Marreco Avatar answered Oct 07 '22 17:10

Fabio Marreco