0

I am trying to have a Ruby script lpush a json payload to redis via redis-cli, but somehow I'm not getting the quotes right:

timestamp = `date +%s.%N`.strip
jid = `cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 24 | head -n 1`.strip
json = "{\"retry\":true,\"queue\":\"tests\",\"class\":\"TestRunnerJob\",\"args\":[#{ARGV[0].to_i}],\"jid\":\"#{jid}\",\"enqueued_at\":#{timestamp}}"
cmd = <<-eos
 echo lpush "queue:tests" \"#{json}\" |redis-cli -h localhost -n 12 -d ';'
eos

p `#{cmd.strip}`

I must be messing up the quoting somehow, but I don't see where.

Jochen
  • 1,853
  • 3
  • 20
  • 28

1 Answers1

1

Your json is interpolated twice, getting rid of slashes. Use single quotes around it:

json = '{\"retry\":true,\"queue\":\"tests\",\"class\":\"TestRunnerJob\",\"args\":[#{ARGV[0].to_i}],\"jid\":\"#{jid}\",\"enqueued_at\":#{timestamp}}"'
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160