Skip to content

Instantly share code, notes, and snippets.

@petrushev
Created October 15, 2013 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petrushev/6993277 to your computer and use it in GitHub Desktop.
Save petrushev/6993277 to your computer and use it in GitHub Desktop.
import redis
pool = redis.ConnectionPool(host='localhost', port=6633)
red = redis.StrictRedis(connection_pool = pool)
from datetime import datetime, timedelta
from decimal import Decimal
import time
import calendar
from json import dumps, loads
now_ = datetime.now() # compensate to utc
conv = lambda now__: int(calendar.timegm(now__.timetuple()))
"""
keys = red.keys('bundle:3:2013-09-29:*')
for k in keys:
print k
bundlezset = red.zrangebyscore(k, conv(now_), '+inf')
for id in bundlezset:
content = red.get(id)
try:
bundle = loads(content)
except Exception:
pass
#print 'err:' ,content
else:
if bundle['jb_hotel_id']==19:
print bundle.get('hotel_object_id'), bundle['jb_hotel_id'], bundle['total_amount_before_tax'], bundle['total_amount_after_tax']
"""
def check_ttl_diff():
keys = red.keys('offer:*')
for k in keys:
print k
offerzset = red.zrangebyscore(k, conv(now_), '+inf')
for id in offerzset :
content = red.get(id)
try:
offer = loads(content)
except Exception:
#print 'err:' ,content
pass
else:
#print red.ttl(id), offer['bundle']['_uuid'], red.ttl(offer['bundle']['_uuid'])
print abs(red.ttl(id) - red.ttl(offer['bundle']['_uuid']) )
def check_miss_bundle():
keys = red.keys('offer:*')
errs = []
for k in keys:
offer_zset = red.zrangebyscore(k, conv(now_), '+inf')
for id_ in offer_zset:
content = red.get(id_)
if content is None:
score = red.zscore(k, id_)
d = datetime.fromtimestamp(score)
print d
errs.append(d)
print min(errs), max(errs)
def check_city_offers(city_id):
pattern = 'offer:%d:*' % city_id
for k in red.keys(pattern):
offer_zset = red.zrangebyscore(k, conv(now_), '+inf')
for id_ in offer_zset:
content = red.get(id_)
if content is None: continue
content = loads(content)
print k[-4:], content['n_double_rooms'], content['n_single_rooms']
#print loads(content)
def max_uuid():
max_k = 0
min_k = float('inf')
for k in red.keys('*'):
if not k.isdigit() : continue
k = int(k)
if k > max_k: max_k = k
if k < min_k: min_k = k
print min_k, max_k
def check_offer_price():
keys = red.keys('offer:*')
for k in keys:
offer_zset = red.zrangebyscore(k, conv(now_) , '+inf')
for id_ in offer_zset:
content = red.get(id_)
if content is None: continue
content = loads(content)
if 'price' not in content:
print k, id_
def inspect_competitor():
keys = red.keys('competitor_rate:*:2013-10-15:1:1:*:1')
available = set()
for k in keys:
comp_zset = red.zrangebyscore(k, conv(now_), '+inf')
for id_ in comp_zset:
content = red.get(id_)
if content is None: continue
content = loads(content)
#if k not in available:
# print k
# available.add(k)
#break
print k, id_, red.ttl(id_) / (3600), 'hrs'
available = sorted(available)
for k in available:
print k
# print content['amount_after_tax']
inspect_competitor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment