def check_block(sid, ip): if rds.get(config.BLOCK_PREFIX.format(sid=sid, ip=ip)): return True elif Block.select().where(Block.sid == sid, Block.ip == ip).first(): rds.set(config.BLOCK_PREFIX.format(sid=sid, ip=ip), 1) return True return False
def test_set_up_counts(self): r = range(15, 17) self.send_request( path = self.path, method = 'PUT', data = json.dumps({'cids': r}) ) self.assertEqual(falcon.HTTP_200, self.mock.status) for i in r: k = config.COMMENT_UP_PREFIX.format(sid = self.site.id, cid = i) self.assertEqual(int(rds.get(k)), 1)
def req_rate(req, resp, params): ip = req.get_header('X-Real-IP') if not ip: return key = config.HEAT_KEY.format(ip = ip) current = rds.get(key) if current and int(current) > config.HEAT_MAX: raise falcon.HTTPForbidden(config.HTTP_403, 'ip %s overheat' % ip) if not current: rds.incr(key) rds.expire(key, config.HEAT_TIME) else: rds.incr(key)
def get_comments_by_tid(site, tid, expand, page, num): total = config.COMMENT_COUNT_PREFIX.format(sid = site.id, tid = tid) # We don't care the count, just notify renew page cache count = rds.get(total) or 0 return get_comments(site, count, page, num, tid = tid, expand = expand)