forked from SomajitDey/redis-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis-cli
executable file
·37 lines (24 loc) · 1.05 KB
/
redis-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash
# Brief: REDIS console
# Usage: ./redis-cli -h
. "${BASH_SOURCE%/*}/redis.bash"
trap 'redis_disconnect; pkill -s $$' exit
trap 'echo; exit' HUP TERM QUIT INT
redis_connect "${@}" || exit 1
history -c # Clear Bash history
while read -re -p "${REDIS_HOST}:${REDIS_PORT}_${REDIS_DB:-0}$ " cmd ;do
[[ "${cmd^^}" == @(QUIT|EXIT|Q) ]] && break # ^^ implies all uppercase; @(pattern-list) matches one of the given patterns
history -s "${cmd}" # Append latest command to Bash history
redis_exec "${cmd}" || ((${?} != 22)) || exit 22
if [[ "${cmd,,}" =~ ^([p]?subscribe|monitor).*$ ]]; then
# Push protocol activated
redis_rep -n 0 <& ${REDIS_FD} &
trap 'redis_exec reset && echo "Press Enter">/dev/tty && break' INT # breaks from nested loop below & continues with main loop
# Reading for allowed commands [Ref: https://redis.io/commands/subscribe]
while read -re cmd;do
[[ -n "${cmd}" ]] && printf "%s\r\n" "${cmd}"
done >& ${REDIS_FD}
trap 'echo;exit' INT # Override last trap reset
fi
done
exit