如何使用 bash 命令的输出设置 redis 键

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

我在 bash 脚本中使用 redis-cli,现在我想以特定格式将当前日期保存到特定于 redis 的键中。我怎么做? 我已经尝试 redis-cli -x SET last-modified $(date +"%D %T") 但没有成功。

任何帮助将不胜感激!

试试这个

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

您可以在redis-cli帮助中查看示例,仅显示相关输出

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

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