I just installed the stable version of Redis server, on a Debian 8.7.1. Everything works fine so far. I want to know how I can use the current date and time in a SET entry. For example:

SET test:test "[current date] [current hour + 1]"

Or if there is no option, then is there a workaround?

I don't think there's any more information needed for the question, but if you need anything else, please ask.

Thank you.

1 Answer 1

var="SET test:test \"[$(date +%d.%m.%Y)] [$((($(date +%H)+1)%24))]\""
echo "$var"
    SET test:test "[30.03.2018] [2]"
  • Hi. Thank you for your suggestion but this is a shell command, SET is a redis-cli command and I'm trying to use date and time in there.
    – Amir Amini
    Commented Mar 29, 2018 at 23:28
  • @AmirAmini Sorry, I misunderstood the question. I thought the commands could be prepared in shell code. Commented Mar 30, 2018 at 11:24
  • Thank you, I found the solution and your answer helped me a lot. I put the date and (hour + 1) in 2 different variables and used this command: redis-cli SET test:test "$date $hour"
    – Amir Amini
    Commented Mar 30, 2018 at 21:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .