def check_count(key, max_sent, max_count, forbid_time, default_expire): count = cache.get(key) if count is not None: cache.incr(key) if int(count) < max_sent: return True elif int(count) >= max_count: cache.expire(key, forbid_time) return False else: return False else: cache.setex(key, default_expire, 1) return True
def get_reservation_forecast(keys): if not isinstance(keys, list): keys = list(keys) keys = set( models.AWSKey.query.filter_by( key=k).first() if isinstance(k, basestring) else k for k in keys) if not all(isinstance(k, models.AWSKey) for k in keys): raise TypeError('All keys must be strings or AWSKeys.') cache_key = 'get_reservation_forecast#' + models.MultikeyGroup.id_of(keys) cached = cache.get(cache_key) if cached: unpacked = decompressed_json(cached) else: unpacked = compute_reservation_forecast(keys) cache.setex(cache_key, 12 * 60 * 60, compressed_json(unpacked)) return unpacked
def save_auth_code(phone, code): cache.setex(_add_prefix(phone), _CODE_EXPIRE_TIME, code)
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 set_sms_sended_cache(phone): key = prefix_key('sms_sended_cache:%s' % phone) cache.setex(key, DEFAULT_SMS_SENDED_CACHE_TIMEOUT, True)
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)