-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.py
48 lines (39 loc) · 1.58 KB
/
query.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
42
43
44
45
46
47
48
#!/usr/bin/env python3
##############################################################################
# Based on:
# https://github.com/RedisJSON/redisjson-py
##############################################################################
import argparse
import redis
from r2r_offer_utils.cli_utils import IntRange
if __name__ == '__main__':
REDIS_HOST = 'localhost'
REDIS_PORT = 6379
parser = argparse.ArgumentParser()
parser.add_argument('request_ids',
metavar='<request_id>',
nargs='+',
help='Request ids to query.')
parser.add_argument('-H', '--host',
default=REDIS_HOST,
dest='redis_host',
help=f'Redis hostname [default: {REDIS_HOST}].')
parser.add_argument('--port',
default=REDIS_PORT,
dest='redis_port',
type=IntRange(1, 65536),
help=f'Redis port [default: {REDIS_PORT}].')
args = parser.parse_args()
redis = redis.Redis(host=args.redis_host, port=args.redis_port)
# getting a trip back
# for reqid in args.request_ids:
# offers = redis.lrange(f'{reqid}:offers', 0, -1)
# print(f"* request id: {reqid}")
# for offer in offers:
# print(" - offer id: {}".format(offer.decode('utf-8')))
# print("---")
for reqid in args.request_ids:
user_id = redis.get(f'{reqid}:user_id')
print(f"(request id, user_id): ({reqid}, {user_id}")
print("---")
exit(0)