示例#1
0
def connect(nodes, database=None, table=None):
    """
    Connects to a cluster and optionally sets the database and table
    to be used.
    
    Args:
        nodes (string or list): the controller node(s) in "hostname:port" format
        
        database (string): the name of the database to be used (default=None)
        
        table (string): the name of the table to be used (default=None)
    """
    client = scaliendb.Client(nodes)    
    globals()["client"] = client
    # import client's member functions to the global scope
    members = inspect.getmembers(client, inspect.ismethod)
    for name, func in members:
        if name[0] != "_":
            globals()[name] = TimerFunc(name, func)
    try:
        if database == None:
            return
        globals()["database"] = client.get_database(database)
        if table == None:
            return
        globals()["table"] = client.get_database(database).get_table(table)
    except scaliendb.Error as e:
        print(e)
示例#2
0
import random
import sys
import scaliendb
import time
import string
import csv
from scaliendb_iter import *
	
client = scaliendb.Client(["localhost:7080"])
#client._set_trace(True)
client.use_database("bulk")
client.use_table("1-grams")
lr = scaliendb_iter_keyvalues(client, count=1000)
for k, v in lr:
	#print("%s => %s" % (k, v))
	
示例#3
0
文件: set.py 项目: zYg-sys/scaliendb
import scaliendb
import time

client = scaliendb.Client(["127.0.0.1:7080"])

client.use_database("test")
client.use_table("test")
client.truncate_table("test")

starttime = time.time()
for i in xrange(1345):
    client.set(i, i * i)
client.submit()
endtime = time.time()
elapsed = endtime - starttime
print(elapsed)
示例#4
0

def sizeof_fmt(num):
    for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
        if num < 1024.0:
            return "%3.1f%s" % (num, x)
        num /= 1024.0


limit = 0
start = 0
if len(sys.argv) > 1:
    limit = int(sys.argv[1])
    if len(sys.argv) > 2:
        start = int(sys.argv[2])
client = scaliendb.Client(CONTROLLERS)
#client._set_trace(True)

if False:
    quorum_id = client.create_quorum(["100"])
    database_id = client.create_database("testdb")
    client.create_table(database_id, quorum_id, "testtable")

client.use_database("testdb")
client.use_table("testtable")
sent = 0
value = "%100s" % " "
i = start
batch = 10000
starttime = time.time()
rnd = random.randint(1, 1000000000)