def get_appid_balance(appid): real_pay_list = REAL_PAY.to_dict().keys() balance = 0.0 for real_pay in real_pay_list: key = prefix_key('appid:%s:real_pay:%s' % (appid, real_pay)) balance += float(cache.get(key) or 0) return balance
def incr_alipay_today_amount(alipayid, amount): key = prefix_key('alipay:%s' % alipayid) exists = cache.exists(key) ret = cache.incrbyfloat(key, float(amount)) if not exists: ttl = tz.left_seconds_today() cache.expire(key, ttl) return ret
def fresh_overload_alipay_set(alipayid): key = prefix_key('alipay:overload') exists = cache.exists(key) ret = cache.sadd(key, alipayid) if not exists: ttl = tz.left_seconds_today() cache.expire(key, ttl) return ret
def get_sms_sended_cache(phone): key = prefix_key('sms_sended_cache:%s' % phone) return cache.get(key)
def get_otp_token(account_id): key = prefix_key('uid:%s:otptoken' % account_id) return cache.get(key)
def _add_prefix(key, isIp=False): if isIp: return prefix_key('ip:%s' % key) else: return prefix_key('phone:%s' % key)
def generate_otp_token(account_id): key = prefix_key('uid:%s:otptoken' % account_id) token = uuid4().hex cache.setex(key, 60, token) return token
def check_phone_count(phone): key = prefix_key('phonecount:%s' % phone) phone_check = check_count(key, 10, 20, 12 * 3600, 12 * 3600) return phone_check
def pop_expired_events(event_type, max_time): key = prefix_key('timerzset:%s' % event_type) resp = cache.zrangebyscore(key, 0, max_time) if resp: cache.zrem(key, *resp) return resp
def exist_any_event(event_type): key = prefix_key('timerzset:%s' % event_type) return cache.zcard(key) > 0
def submit_timer_event(event_type, cache_value, timestamp): key = prefix_key('timerzset:%s' % event_type) return cache.zadd(key, timestamp, cache_value)
def set_sms_sended_cache(phone): key = prefix_key('sms_sended_cache:%s' % phone) cache.setex(key, DEFAULT_SMS_SENDED_CACHE_TIMEOUT, True)
def get_cache_code(id): key = prefix_key('id_cache:%s' % id) code = cache.get(key) or 'F**K' return code
def cache_id_code(id, code): key = prefix_key('id_cache:%s' % id) cache.setex(key, DEFAULT_CACHE_TIMEOUT, code)
def set_sms_cache(phone, value=True): key = prefix_key('sms_cache:%s' % phone) cache.setex(key, DEFAULT_SMS_CACHE_TIMEOUT, value)
def set_alipay_qr(payid, qrCode): key = prefix_key('payid:%s' % payid) return cache.setex(key, 3600, qrCode)
def get_alipay_qr(payid): key = prefix_key('payid:%s' % payid) return cache.get(key)
def get_overload_alipay_set(): key = prefix_key('alipay:overload') return cache.smembers(key)
def set_appid_balance(appid, real_pay, balance): key = prefix_key('appid:%s:real_pay:%s' % (appid, real_pay)) return cache.set(key, balance)
def replace_timer_event(event_type, cache_value, timestamp): key = prefix_key('timerzset:%s' % event_type) cache.delete(key) return cache.zadd(key, timestamp, cache_value)
def get_last_succ(account_id): key = prefix_key('uid:%s:lastsucc' % account_id) return cache.hgetall(key)
def appid_generator(): key = prefix_key('appid:pay') return cache.incr(key)
def save_last_succ(account_id, drift, succ): key = prefix_key('uid:%s:lastsucc' % account_id) cache.hmset(key, {'drift': drift, 'succ': succ}) cache.expire(key, 600)
def timer_event_processed(event_id): key = prefix_key('timerlock:%s' % event_id) return not cache.setnx(key, int(time.time()))
def check_ip_count(ip): # short_key = _add_prefix(ip, True) # short_check = check_count(short_key, _MAX_SENT, _MAX_COUNT, _FORBID_TIME, _IP_EXPIRE_TIME) long_key = prefix_key('ipcount:%s' % ip) long_check = check_count(long_key, 6, 10, 3600, 3600) return long_check