redis-pipe:像Unix Pipes一样对待 Redis Lists
cm54
10年前
redis-pipe可以让你处理Redis的列表,好像他们是Unix的管道。它基本上是利用LPUSH和LPOP连接 stdin 与 stdout。
How it works
Configuration
Set theREDIS_HOSTandREDIS_PORTenvironment variables for easy configuration or pass--hostand--portarguments.
Writing from stdin to Redis List
Pipe in value toredis-pipeand it willLPUSHthem to the Redis List.
echo "hi there" | ./redis-pipe greetings
Reading from Redis List to stdout
If you callredis-pipewith a tty attached it willLPOPall values from the Redis List and write them to stdout.
./redis-pipe greetings
You can also limit the amount of values popped from the list.
./redis-pipe --count 100 greetings
Support for blocking mode withBLPOPis not supported yet.
Examples
Centralized Logging
In this sample we pipe the syslog to a Redis List calledlogs.
tail -f /var/log/syslog | ./redis-pipe logs
You can now easily collect all the syslogs of your machines on a single server.
./redis-pipe logs > logs.txt
Very basic job queue
Create jobs and store them.
cat jobs.txt | ./redis-pipe jobs
Process jobs on several workers and store the results.
./redis-pipe --count 10 jobs | python do-work.py | ./redis-pipe results
Collect the results.
./redis-pipe results > results.txt