def test_list():
    lightcloud.list_varnish('hello')

    lightcloud.list_add('hello', ['1', '2', '3'])
    lightcloud.list_add('hello', ['4'])
    assert lightcloud.list_get('hello') == ['4', '1', '2', '3']

    lightcloud.list_remove('hello', ['3'])
    assert lightcloud.list_get('hello') == ['4', '1', '2']
Beispiel #2
0
def test_list():
    lightcloud.list_varnish('hello')

    lightcloud.list_add('hello', ['1', '2', '3'])
    lightcloud.list_add('hello', ['4'])
    assert lightcloud.list_get('hello') == ['4', '1', '2', '3']

    lightcloud.list_remove('hello', ['3'])
    assert lightcloud.list_get('hello') == ['4', '1', '2']
Beispiel #3
0
def register_offend(key, extra_data='', system='default'):
    """Register an offend for `key`. `data` should be an integer or a string.
    """
    now = get_unixtime(datetime.utcnow())

    if extra_data:
        current_offends = get_offends(key, system)
        #Don't count duplicates
        for offend in current_offends:
            if offend[1] == extra_data:
                return

    lightcloud.list_add('offends_%s' % key, ['%s///%s' % (now, extra_data)],
                        system=system)
Beispiel #4
0
def register_offend(key, extra_data='', system='default'):
    """Register an offend for `key`. `data` should be an integer or a string.
    """
    now = get_unixtime(datetime.utcnow())

    if extra_data:
        current_offends = get_offends(key, system)
        #Don't count duplicates
        for offend in current_offends:
            if offend[1] == extra_data:
                return

    lightcloud.list_add('offends_%s' % key,
                        ['%s///%s' % (now, extra_data)],
                        system=system)
Beispiel #5
0
def test_limit_add():
    lightcloud.list_varnish('hello')

    for i in range(0, 250):
        lightcloud.list_add('hello', [i])
    assert len(lightcloud.list_get('hello')) == 200

    lightcloud.list_varnish('hello')
    for i in range(0, 100):
        lightcloud.list_add('hello', [i], limit=50)
    assert len(lightcloud.list_get('hello')) == 50

    cur = lightcloud.list_get('hello')
    i = 100
    for elm in cur:
        i -= 1
        assert elm == str(i)
def test_limit_add():
    lightcloud.list_varnish('hello')

    for i in range(0, 250):
        lightcloud.list_add('hello', [i])
    assert len(lightcloud.list_get('hello')) == 200

    lightcloud.list_varnish('hello')
    for i in range(0, 100):
        lightcloud.list_add('hello', [i], limit=50)
    assert len(lightcloud.list_get('hello')) == 50

    cur = lightcloud.list_get('hello')
    i = 100
    for elm in cur:
        i -= 1
        assert elm == str(i)
Beispiel #7
0
 def put(self, key, value):
     """
     Put a key/value pairs into the lightcloud storage backend
     
     @return: True if the item put successfully, False otherwise
     """
     #first try to get the the list of items stored for this key if any, then add the new value to the list otherwise add the new key/value to the store
     return lightcloud.list_add(key, [value]) == 'ok'
Beispiel #8
0
 def put(self, key, value):
     """
     Put a key/value pairs into the lightcloud storage backend
     
     @return: True if the item put successfully, False otherwise
     """
     #first try to get the the list of items stored for this key if any, then add the new value to the list otherwise add the new key/value to the store
     return lightcloud.list_add(key, [value]) == 'ok'
Beispiel #9
0
    print 'Finished "%s" %s times in %0.2f sec [%0.1f operations pr.sec]' %\
            (name, times_run, end, pr_sec)


#--- Support ----------------------------------------------
generic_bench('Tyrant set', 10000,
              lambda: lightcloud.set('hello', 'world', system='tyrant'))
generic_bench('Redis set', 10000,
              lambda: lightcloud.set('hello', 'world', system='redis'))

print '------'

generic_bench('Tyrant get', 10000,
              lambda: lightcloud.get('hello', system='tyrant'))
generic_bench('Redis get', 10000,
              lambda: lightcloud.get('hello', system='redis'))

print '------'

generic_bench('Tyrant list_add', 10000,
              lambda: lightcloud.list_add('hello_l', ['1'], system='tyrant'))
generic_bench('Redis list_add', 10000,
              lambda: lightcloud.list_add('hello_l', ['1'], system='redis'))

print '------'

generic_bench('Tyrant delete', 10000,
              lambda: lightcloud.delete('hello', system='tyrant'))
generic_bench('Redis delete', 10000,
              lambda: lightcloud.delete('hello', system='redis'))
Beispiel #10
0
    print 'Finished "%s" %s times in %0.2f sec [%0.1f operations pr.sec]' %\
            (name, times_run, end, pr_sec)


#--- Support ----------------------------------------------
generic_bench('Tyrant set', 10000,
              lambda: lightcloud.set('hello', 'world', system='tyrant'))
generic_bench('Redis set', 10000,
              lambda: lightcloud.set('hello', 'world', system='redis'))

print '------'

generic_bench('Tyrant get', 10000,
              lambda: lightcloud.get('hello', system='tyrant'))
generic_bench('Redis get', 10000,
              lambda: lightcloud.get('hello', system='redis'))

print '------'

generic_bench('Tyrant list_add', 10000,
              lambda: lightcloud.list_add('hello_l', ['1'], system='tyrant'))
generic_bench('Redis list_add', 10000,
              lambda: lightcloud.list_add('hello_l', ['1'], system='redis'))

print '------'

generic_bench('Tyrant delete', 10000,
              lambda: lightcloud.delete('hello', system='tyrant'))
generic_bench('Redis delete', 10000,
              lambda: lightcloud.delete('hello', system='redis'))