def _get_data(self): r = mc.get(SCRETDB_MC_KEY % self.props_name) if r: return r r = self.secret_db.get(self.props_name) or {} mc.set(SCRETDB_MC_KEY % self.props_name, r) return r
def get_by_rev(self, rev): r = mc.get(SCRETDB_MC_REV_KEY % (self.props_name, rev)) if r: return r r = self.secret_db.get(self.props_name, rev=rev) mc.set(SCRETDB_MC_REV_KEY % (self.props_name, rev), r) return r
def get_ticket(): ticket = mc.get(CACHE_TICKET_KEY) if ticket: return ticket response = weixin_api.get_js_ticket() if response['errcode'] != 0: raise RuntimeError('weixin error: %r' % response) ticket = response['ticket'] expires_in = response['expires_in'] mc.set( CACHE_TICKET_KEY, ticket, ) mc.expire(CACHE_TICKET_KEY, expires_in) return ticket
def fetch_account_info(profile): """fetch all of the account order info""" yixin_account = YixinAccount.get_by_local(profile.account_id) if not yixin_account: return fetch_status = mc.get( MC_FETCH_ACCOUNT_STATUS_BY_USER.format(user_id=profile.account_id)) if fetch_status: return profile.person_account_info response = yixin.client.query.account_info(token=yixin_account.p2p_token, timeout=15) profile.person_account_info = response.data.p2pservice_list sync_orders_by_account_info(profile) # set fetch status with expire time mc.set(MC_FETCH_ACCOUNT_STATUS_BY_USER.format(user_id=profile.account_id), True) return profile.person_account_info
def disable(self): mc.set(self.key, False)
def enable(self): mc.set(self.key, True)
def request_bind(uid, mobile, is_send_sms=True): mc.set(MC_BIND_MOBILE_BY_USER % uid, mobile) if is_send_sms: sms = ShortMessage.create(mobile, mobile_bind_sms, user_id=uid) sms.send()
def tokensetter(app_id, app_secret, access_token, expires_in): mc.set(CACHE_ACCESS_TOKEN_KEY, access_token) mc.expire(CACHE_ACCESS_TOKEN_KEY, expires_in)
def generate(self, secret): image_io, code = self._gen() mc.set(_MC_CAPTCHA_KEY % secret, code) mc.expire(_MC_CAPTCHA_KEY % secret, self.expire) return image_io
def incr_user_count(): mc.set(USER_COUNT_MC_KEY, get_user_count()+1)
def set_total_ins_children_count(): """set total user count who buy children insurance""" mc.set(MC_TOTAL_INSURANCE_USER_COUNT, get_total_ins_children_count() + 1)
def upload(self, data, mime_type, key=None): key = key or gen_salt(16) mc.set('%s:%s' % (self.bucket_name, key), data) return {}
def _save_token(self, token): key = self._token_rds_key.format(self) data = json.dumps(token) mc.set(key, data) mc.expireat(key, int(token['expires_at']))
def open_time(self, open_time): mc.set(self.open_time_key, open_time)
def mark_as_read(self, user_id): mc.set(FUNDWEEKLY_READ_CACHE_KEY % (self.id, user_id), True)
def close_time(self, close_time): mc.set(self.close_time_key, close_time)
def voucher(self, base): mc.set(self.key, base)