-
Notifications
You must be signed in to change notification settings - Fork 3
/
toredis.py
executable file
·41 lines (32 loc) · 1.35 KB
/
toredis.py
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
38
39
40
41
#!/usr/bin/env python
import sys
import redis
import argparse
parser = argparse.ArgumentParser(
description='Pushes data from stdin to redis channels'
)
parser.add_argument('channels',
metavar='channel', nargs='+',
help='the channels/lists to publish the data on')
parser.add_argument('--host',
dest='host', default='tools-redis',
help='the host name of the redis server')
parser.add_argument('--port',
dest='port', type=int, default=6379,
help='the port number of the redis server')
parser.add_argument('--method',
dest='method', default='publish',
choices=['append', 'lpush', 'lpushx', 'rpush', 'rpushx',
'sadd', 'pfadd', 'publish'],
help="method used to store data. See redis docs for "
"details. rpush (add to the end of a list) and "
"publish (send to subscribers) are most useful. "
"Default is 'publish'.")
args = parser.parse_args()
# Redis does not support streaming binary data, so we have to fully
# read the input.
data = sys.stdin.read()
r = redis.Redis(host=args.host, port=args.port)
method = getattr(r, args.method)
for channel in args.channels:
method(channel, data)