Пример #1
0
 def _get_pv(self):
     key = self._post_pv_by_id_cache_key % self.id
     cached = int(rd.get(key)) if rd.get(key) else None
     if cached is not None:
         return cached
     rd.set(key, self.pv_)
     return self.pv_
Пример #2
0
 def _set_pv(self, pv_):
     rd.set(self._post_pv_by_id_cache_key % self.id, pv_)
     if pv_ % 7 == 0:
         self.pv_ = pv_
         db.session.add(self)
         db.session.commit()
         self.clear_cache()
Пример #3
0
 def remaining_viewcount(self):
     cache_key = self._remaining_viewcount_by_student_cache_key % self.id
     if rd.get(cache_key):
         viewcount = int(rd.get(cache_key))
         return viewcount
     else:
         rd.set(cache_key, self.MAX_VIEWCOUNT)
         rd.expire(cache_key, ONE_DAY)
         return self.MAX_VIEWCOUNT
Пример #4
0
    def add(cls, mobile, type_, max_send_total=5):
        total_send_key = cls._total_send_key.format(mobile=mobile,
                                                    type_=type_.value)
        total_send = int(
            rd.get(total_send_key)) if rd.get(total_send_key) else 0
        # if total_send and total_send >= max_send_total:
        #     raise SendSMSTooManyTimesError(
        #         '已超出当日最大获取验证码次数,请24小时后尝试')

        code = cls._gen_verify_code()
        key = cls._redis_key.format(mobile=mobile, type_=type_.value)
        existed = rd.get(key)
        if existed:
            rd.delete(key)
        rd.set(key, code)
        rd.expire(key, cls._expire_time)

        rd.incr(total_send_key)
        if not total_send:
            rd.expire(total_send_key, ONE_DAY)
        return code