Redis LASTSAVE Command Explained

When using Redis, we can use the LASTSAVE command to get the Unix time of the last DB save.

More specifically, LASTSAVE returns the Unix time of the last DB save executed with success.

Syntax

The syntax goes like this:

LASTSAVE

So we run it on its own, without any other options.

Example

Here’s an example to demonstrate:

LASTSAVE

Result:

(integer) 1654826346

The result is an integer reply with the Unix time of the last DB save executed with success.

Let’s run another command that saves data to the DB:

SET type "dog"

And now let’s run LASTSAVE again:

LASTSAVE

We get a different Unix timestamp:

(integer) 1654832549

However, if we simply get the value (without changing anything):

GET type

And run LASTSAVE again:

LASTSAVE

We get the same Unix timestamp:

(integer) 1654832549