예제 #1
0
def run(mc):
    print('run')

    mc.set('cnt', 0)
    mc.incr('cnt', 2)
    mc.decr('cnt', 5)
    print(mc.get('cnt'))
예제 #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")
예제 #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")
예제 #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")
예제 #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")
예제 #6
0
파일: base.py 프로젝트: jpgerek/gae-common
 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)
예제 #7
0
def run(mc):
    print('run')

    mc.set('key', 'abc')
    mc.delete('key')
    print(mc.get('key'))
예제 #8
0
def run(mc):
    mc.set('cnt', 0)
    mc.incr('cnt', 2)
    mc.decr('cnt', 5)
예제 #9
0
def run(mc):
    print('run')

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