Skip to content

Commit

Permalink
start adding support for multiple file input
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Luft committed Aug 28, 2011
1 parent d61bca7 commit b486c78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions bin/redis-import
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import argparse
import sys
import fileinput

from redline import commands

Expand All @@ -19,11 +20,19 @@ if __name__ == '__main__':
help='Redis command')
parser.add_argument('key',
help='name of the key for the command')

parser.add_argument('infiles', nargs='*',
#type=argparse.FileType('r'),
#default=sys.stdin,
metavar='FILE')
options = parser.parse_args()

cmd = options.cmd
if cmd == 'set':
commands.load_set(options.key, sys.stdin, batch_size=options.batch_size)
print sys.argv
if len(sys.argv) > 3:
input_set = fileinput.input(sys.argv[3:])
else:
input_set = sys.stdin
commands.load_set(options.key, input_set, batch_size=options.batch_size)
elif cmd == 'list':
commands.load_list(options.key, sys.stdin, batch_size=options.batch_size)
6 changes: 3 additions & 3 deletions redline/commands.py
Expand Up @@ -12,12 +12,12 @@ def load_set(key, IN, **kwargs):
r = redis.Redis()
pipeline_redis = r.pipeline()
count = 0
#batch_size = kwargs['batch_size']
batch_size = kwargs.get('batch_size', 1000)

seen = set([None])
for member, _ in groupby(reader(IN, delimiter='\t'),
lambda x: x[0] if len(x) else None):
reader_files = reader(IN, delimiter='\t')
for member, _ in groupby(reader_files,
lambda x: x[0] if len(x) else None):
if member not in seen:
pipeline_redis.sadd(key, member.rstrip())
count += 1
Expand Down

0 comments on commit b486c78

Please sign in to comment.