def _train_total(self, tags): if not tags: return key = cache_key(TRAIN_TOTAL, items=None) if len(tags) == 1: value = tags.values()[0] cache.incr(name=key, amount=int(value)) return values = tags.values() total = reduce(lambda x, y: x+y, values) cache.incr(name=key, amount=int(total))
def register(_data): if not cache.exists(session['username']): log.info('设置register_data[session[\'username\']]为空') cache.set(session['username'] + '.count', 0, ex=600) # expires in 10 minutes session['action'] = 'register' if verify(_data): cache.rpush(session['username'], json.dumps(_data)) cache.incr(session['username'] + '.count') log.info('获取到了一组合法签名数据') log.debug(_data) if int(cache.get(session['username'] + '.count')) >= 3: log.info('获取到了三组信息,成功注册') log.debug('所有数据:') register_data = cache.lrange(session['username'], 0, -1) register_data = [json.loads(i) for i in register_data] log.debug(register_data) cache.delete(session['username']) cache.delete(session['username'] + '.count') real = DynamicProcess.prepare_list(register_data) real_v = DynamicProcess.prepare_value(real) execute_sql( "INSERT INTO user (username, password, sign_prepared, sign_val) values (\ %(username)s, %(password)s, %(sign_prepared)s, %(sign_val)s\ )", username=session['username'], password=session['password'], sign_prepared=json.dumps(real), sign_val=real_v) session.pop('username') session.pop('password') return 'ret' return 'continue'
def _train_rate(self, tags): for tag in tags: key = cache_key(TRAIN_TAG_PREFIX, tag) value = int(tags[tag]) cache.incr(name=key, amount=value)