Redis: who is eating my field when piping llen results through awk? Redis: who is eating my field when piping llen results through awk? shell shell

Redis: who is eating my field when piping llen results through awk?


What you're experiencing is redis-cli selecting different outputs depending on what STDOUT is. If STDOUT is a TTY, redis-cli will output using it's "standard" formatting. Otherwise, the "raw" formatting is the default:

--raw            Use raw formatting for replies (default when STDOUT is not a tty)

As you see from the help, or the above, you can specify --raw to always have it output the "raw" format (without type qualifiers, etc). What I found out digging through the source for this, is that there is also a CSV mode, using redis-cli --csv.

Edit: To force the "standard" output, even when STDOUT is not a TTY, you can set the environment variable FAKETTY:

FAKETTY=1 redis-cli llen some_list | awk '{ print $2 }'

Or

redis-cli --raw llen some_list | awk '{ print $1 }'