Getting values from a redis server is also possible in (bash) shell scripts. On Github, I found a project providing two files (redis-bash-lib and
redis-bash-cli) which enable such functionality. I wrote a small script that monitors a key for changes and writes a message to the screen, if the monitored key changes:
#!/bin/bash
SOMEVAR=''
OLDVAR=''
while /bin/true; do
SOMEVAR=`redis-bash-cli -h localhost GET testkey`;
if [ "$SOMEVAR" != "$OLDVAR" ]
then
echo "Value has changed from $OLDVAR to $SOMEVAR";
fi
OLDVAR=$SOMEVAR;
sleep 1;
done;
Just open a terminal, start "redis-cli" und enter "set testkey perhaps", "set testkey again" or any other values and see how the script reacts to that change.
You could use redis server to exchange commands between some other software and your script. The script could evaluate the value and execute commands.

Keine Kommentare:
Kommentar veröffentlichen