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.

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 Mar 29 '18 at 23:28
  • @AmirAmini Sorry, I misunderstood the question. I thought the commands could be prepared in shell code. – Hauke Laging Mar 30 '18 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 Mar 30 '18 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.