Home > Mobile >  How to set redis key with the output of a bash command
How to set redis key with the output of a bash command

Time:05-30

I'm using redis-cli within a bash script, now I want to save the current date in a specific format into a redis specific key. how do I do that? I already tried redis-cli -x SET last-modified $(date "%D %T") but without success.

Any help will be appreciated!

CodePudding user response:

Try this

date  "%D %T" | redis-cli -x SET last-modified
OK
redis-cli GET last-modified
"05/30/22 08:32:05\n"

You can see an example in redis-cli help, only relevant output is presented

redis-cli --help
  -x                 Read last argument from STDIN (see example below).

Examples:
  cat /etc/passwd | redis-cli -x set mypasswd
  • Related