예제 #1
0
파일: squash.py 프로젝트: qoelet/squash
	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
예제 #2
0
 def get(self, key):
     """
     Retrieves the value of a key from the lightcloud store
     
     @param key: the key to retrieve
     
     @return: list of the value(s) if exist,  empty list otherwise
     """
     #try to retrieve a list of the values, if the key doesnt exist in the list keys then try to get it from the normal keys
     result = lightcloud.list_get(key)
     if isinstance(result, list):
         return result
     result = lightcloud.get(key)
     if result:
         return [result]
     return list()
예제 #3
0
 def get(self, key):
     """
     Retrieves the value of a key from the lightcloud store
     
     @param key: the key to retrieve
     
     @return: list of the value(s) if exist,  empty list otherwise
     """
     #try to retrieve a list of the values, if the key doesnt exist in the list keys then try to get it from the normal keys
     result = lightcloud.list_get(key)
     if isinstance(result, list):
         return result
     result = lightcloud.get(key)
     if result:
         return [result]
     return list()
예제 #4
0
파일: squash.py 프로젝트: qoelet/squash
	def getfrom_lightcloud(self, shorturlid):
		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 db key
		db_key = self._unsquash(shorturlid)
		# return url or None
		fullurl = None
		fullurl = lightcloud.get(str(db_key))

		# return url
		return fullurl	
예제 #5
0
def get_day_counts(key, offset=None, limit=10, system='default'):
    if not offset:
        offset = _get_now()

    result = []
    for i in xrange(0, limit):
        day_key = '%s_%s' % (_key(key), _format_date(offset))

        count = lightcloud.get(day_key, system=system) or 0
        if count:
            count = long(count)

        result.append({
            'date': datetime(*offset.timetuple()[0:7]),
            'counts': count
        })

        offset = _previous_day(offset)

    return result
예제 #6
0
def get_day_counts(key, offset=None, limit=10, system='default'):
    if not offset:
        offset = _get_now()

    result = []
    for i in xrange(0, limit):
        day_key = '%s_%s' % (_key(key), _format_date(offset))

        count = lightcloud.get(day_key, system=system) or 0
        if count:
            count = long(count)

        result.append({
            'date': datetime(*offset.timetuple()[0:7]),
            'counts': count
        })

        offset = _previous_day(offset)

    return result
예제 #7
0
def test_incr():
    lightcloud.incr('hello', 2)
    assert lightcloud.get('hello') == '2'

    lightcloud.incr('hello', 2)
    assert lightcloud.get('hello') == '4'
예제 #8
0
def test_delete():
    lightcloud.delete('hello')
    assert lightcloud.get('hello') == None
예제 #9
0
def test_set_get():
    lightcloud.set('hello', 'world')
    assert lightcloud.get('hello') == 'world'
예제 #10
0
    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,
              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,
예제 #11
0
def test_incr():
    lightcloud.incr('hello', 2)
    assert lightcloud.get('hello') == '2'

    lightcloud.incr('hello', 2)
    assert lightcloud.get('hello') == '4'
예제 #12
0
def test_delete():
    lightcloud.delete('hello')
    assert lightcloud.get('hello') == None
예제 #13
0
def test_set_get():
    lightcloud.set('hello', 'world')
    assert lightcloud.get('hello') == 'world'
예제 #14
0
def get_counts(key, system='default'):
    count = lightcloud.get(_key(key), system=system)
    if count:
        return long(count)
    return 0
예제 #15
0
    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,
              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,
예제 #16
0
def get_counts(key, system='default'):
    count = lightcloud.get(_key(key), system=system)
    if count:
        return long(count)
    return 0