redis-cli should have a nonzero exit code on error

Created on 9 Jan 2015  路  4Comments  路  Source: redis/redis

Observe:

% echo ping |redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
% echo $?
0

This makes redis-cli pretty useless for scripting.

All 4 comments

Well, just pass the command as an argument then:

[~]% redis-cli ping; echo $?
Could not connect to Redis at 127.0.0.1:6379: Connection refused
1
[~]% redis-server&
[~]% redis-cli ping; echo $?
PONG
0

Thanks, that should do it.

It seems that this behaviour can still be seen in some cases (when trying to flush all keys on slave instance):

$ redis-cli -p 6379 flushall ; echo $?
(error) READONLY You can't write against a read only slave.
0

$redis-cli --version
redis-cli 2.8.19

redis-cli has over 70 different exit points, so there's no clean way to do the right thing everywhere. If some of them aren't working for you, feel free to fix the exit values and open a PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eitijupaenoithoowohd picture eitijupaenoithoowohd  路  4Comments

steadyrun picture steadyrun  路  4Comments

ShockwaveNN picture ShockwaveNN  路  3Comments

shaharmor picture shaharmor  路  3Comments

kalondar picture kalondar  路  3Comments