def run(mc): print('run') mc.set('cnt', 0) mc.incr('cnt', 2) mc.decr('cnt', 5) print(mc.get('cnt'))
def run(mc): print('run') # write 1kb entry v = 1024 * 'a' if not mc.set('test_key', v): raise RuntimeError("failed to set value")
def run(mc): print('run') # write 1kb entry v = 1024*'a' if not mc.set('test_key', v): raise RuntimeError("failed to set value")
def run(mc): print('run') # write 2kb entry v = 2046 * 'a' if not mc.set('test_key', v): raise RuntimeError("failed to set value") if v != mc.get('test_key'): raise RuntimeError("returned value differs")
def wrapper(*args, **kwargs): timestamp = int(time.time()) self = args[0] #- Check if the ip was banned -# ip_ban_key_name = constants.mc.IP_BAN % self.request.remote_addr ban = mc.get(ip_ban_key_name) if ban: #- Renew the ban if it's going to expire in 1/3 of the banning time -# ban_pending_time = ban_time - (timestamp - ban) if ban_pending_time < (ban_time/3): #- Renewing the ban because the attacker insists -# mc.set(ip_ban_key_name, time.time(), ban_time) self.abort(403) current_minute = timestamp - (timestamp%60) key_name = constants.mc.REQUEST_HIT_FROM_IP % (current_minute, self.request.path, self.request.remote_addr) #- Increases hits from an ip to a particular url -# counter = mc.incr(key_name) if counter > limit_per_minute: #- Banning ip -# mc.set(ip_ban_key_name, time.time(), ban_time) self.abort(403) else: return fn(*args, **kwargs)
def run(mc): print('run') mc.set('key', 'abc') mc.delete('key') print(mc.get('key'))
def run(mc): mc.set('cnt', 0) mc.incr('cnt', 2) mc.decr('cnt', 5)
def run(mc): print('run') mc.set('key', 'abc') mc.delete('key')
def run(mc): print('run') mc.set('key', 'abc') print(mc.get('key')) print(mc.get_stats())