Ejemplo n.º 1
0
def run(mc):
    print('run')

    mc.set('cnt', 0)
    mc.incr('cnt', 2)
    mc.decr('cnt', 5)
    print(mc.get('cnt'))
Ejemplo n.º 2
0
def run(mc):
    print('run')

    # write 1kb entry
    v = 1024 * 'a'
    if not mc.set('test_key', v):
        raise RuntimeError("failed to set value")
Ejemplo n.º 3
0
def run(mc):
    print('run')

    # write 1kb entry
    v = 1024*'a'
    if not mc.set('test_key', v):
        raise RuntimeError("failed to set value")
Ejemplo n.º 4
0
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")
Ejemplo n.º 5
0
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")
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
def run(mc):
    print('run')

    mc.set('key', 'abc')
    mc.delete('key')
    print(mc.get('key'))
Ejemplo n.º 8
0
def run(mc):
    mc.set('cnt', 0)
    mc.incr('cnt', 2)
    mc.decr('cnt', 5)
Ejemplo n.º 9
0
def run(mc):
    print('run')

    mc.set('key', 'abc')
    mc.delete('key')
Ejemplo n.º 10
0
def run(mc):
    print('run')
    mc.set('key', 'abc')
    print(mc.get('key'))
    print(mc.get_stats())
Ejemplo n.º 11
0
def run(mc):
    print('run')
    mc.set('key', 'abc')
    print(mc.get('key'))
    print(mc.get_stats())
Ejemplo n.º 12
0
def run(mc):
    mc.set('cnt', 0)
    mc.incr('cnt', 2)
    mc.decr('cnt', 5)