import osimport linecacheimport timefrom SSDB import SSDBssdb = SSDB('127.0.0.1', 8888)print("start")start = time.clock()cache_data = linecache.getlines("/usr/local/access.log")for line in range(len(cache_data)): ssdb.request('set', ['log_'+str(line), cache_data[line].strip('\n')]) print(str(line)) end = time.clock()print "read: %f s" % (end - start)print("ok")
SSDB模块在Python使用方法
下载地址:
使用方法:
import os, sysfrom sys import stdin, stdoutfrom SSDB import SSDBtry: pass ssdb = SSDB('127.0.0.1', 8888)except Exception , e: pass print e sys.exit(0)print ssdb.request('set', ['test', '123'])print ssdb.request('get', ['test'])print ssdb.request('incr', ['test', '1'])print ssdb.request('decr', ['test', '1'])print ssdb.request('scan', ['a', 'z', 10])print ssdb.request('rscan', ['z', 'a', 10])print ssdb.request('keys', ['a', 'z', 10])print ssdb.request('del', ['test'])print ssdb.request('get', ['test'])print "\n"print ssdb.request('zset', ['test', 'a', 20])print ssdb.request('zget', ['test', 'a'])print ssdb.request('zincr', ['test', 'a', 20])print ssdb.request('zdecr', ['test', 'a', 20])print ssdb.request('zscan', ['test', 'a', 0, 100, 10])print ssdb.request('zrscan', ['test', 'a', 100, 0, 10])print ssdb.request('zkeys', ['test', 'a', 0, 100, 10])print ssdb.request('zdel', ['test', 'a'])print ssdb.request('zget', ['test', 'a'])print "\n"print ssdb.request('hset', ['test', 'a', 20])print ssdb.request('hget', ['test', 'a'])print ssdb.request('hincr', ['test', 'a', 20])print ssdb.request('hdecr', ['test', 'a', 20])print ssdb.request('hscan', ['test', '0', 'z', 10])print ssdb.request('hrscan', ['test', 'z', '0', 10])print ssdb.request('hkeys', ['test', '0', 'z', 10])print ssdb.request('hdel', ['test', 'a'])print ssdb.request('hget', ['test', 'a'])print "\n"