Python读取文件内容并将内容插入到SSDB中

import os
import linecache
import time
from SSDB import SSDB ssdb = 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使用方法

下载地址:

http://pan.baidu.com/s/1bFdSQy

使用方法:

import os, sys
from sys import stdin, stdout from SSDB import SSDB
try:
pass
ssdb = SSDB('127.0.0.1', 8888)
except Exception , e:
pass
print e
sys.exit(0)
print ssdb.request('set', ['test', ''])
print ssdb.request('get', ['test'])
print ssdb.request('incr', ['test', ''])
print ssdb.request('decr', ['test', ''])
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', '', 'z', 10])
print ssdb.request('hrscan', ['test', 'z', '', 10])
print ssdb.request('hkeys', ['test', '', 'z', 10])
print ssdb.request('hdel', ['test', 'a'])
print ssdb.request('hget', ['test', 'a'])
print "\n"
上一篇:HTML5 的data-* 自定义属性


下一篇:Oracle 使用小计(2)