Esempio n. 1
0
	def sendto_lightcloud(self, fullurl):
                import lightcloud
                LIGHT_CLOUD = {'lookup1_A': LIGHTCLOUD_LOOKUPS,'storage1_A': LIGHTCLOUD_STORAGES}	

            	lookup_nodes, storage_nodes = lightcloud.generate_nodes(LIGHT_CLOUD)
            	lightcloud.init(lookup_nodes, storage_nodes)
	
            	# get last id and increment
                try:
            	        last_id = lightcloud.get("last_id")
            	        if last_id:
            	                pass
            	        else:
            	           lightcloud.set("last_id","0")     
            	except:
            	        pass
            	next_id = int(last_id) + 1
            	# get shortened url id from current id
            	shortened_url_id = self._squash(next_id)
                try:
            	        # store id, url into db
            	        lightcloud.set(str(next_id),fullurl)
	        
            	        # update last_id
            	        lightcloud.set("last_id", str(next_id))
                except:
                        print "lightcloud update fail"
                        pass

            	# return id
            	return shortened_url_id
Esempio n. 2
0
def test_set_get():
    lightcloud.set('hello', 'world')
    assert lightcloud.get('hello') == 'world'
Esempio n. 3
0

#--- Run the tests ----------------------------------------------
def generic_bench(name, times_run, fn):
    start = time()
    for i in range(0, times_run):
        fn()
    end = time()-start
    pr_sec = float(times_run)/end
    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,
Esempio n. 4
0
def test_set_get():
    lightcloud.set('hello', 'world')
    assert lightcloud.get('hello') == 'world'
Esempio n. 5
0

#--- Run the tests ----------------------------------------------
def generic_bench(name, times_run, fn):
    start = time()
    for i in range(0, times_run):
        fn()
    end = time() - start
    pr_sec = float(times_run) / end
    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,