leakdb是python的一个非常简单和快速的键值存储
LeakDB的Python项目详细描述
为什么?
为了好玩o/
概述
leakdb是python的一个非常简单和快速的键值存储。
所有数据都存储在内存中,持久性由用户定义。 可以为自动刷新定义最大队列大小。
API
>>>fromleakdbimportPersistentQueueStorage>>>leak=PersistentQueueStorage(filename='/tmp/foobar.db')# set the value of a key>>>leak.set('bar',{'foo':'bar'})>>>leak.set('foo',2,key_prefix='bar_')# increment a key>>>leak.incr(key='bar_foo',delta=5)7>>>leak.incr(key='foobar',initial_value=1000)1000# looks up multiple keys>>>leak.get_multi(keys=['bar','foobar']){u'foobar':1000,u'bar':{u'foo':u'bar'}}# ensure changes are sent to disk>>>printleak/tmp/foobar.db12288bytes::3itemsinqueue::3itemsinstoragememory>>>leak.flush(force=True)/tmp/foobar.db12338bytes::0itemsinqueue::3itemsinstoragememory>>>leak.close()
储存
- default storage::默认存储,实现所有的api操作setset_multiincrdecrget_multidelete
- queuestorage::对队列使用DefaultStorage。您可以重写QueueStorage.worker_process方法,并在调用flush方法时生成所需的内容。
fromleakdbimportQueueStorageclassMyQueueStorage(QueueStorage):defworker_process(self,item):""" Default action execute by each worker. Must return a True statement to remove the item, otherwise the worker put the item into the queue. """logger.info('process item :: {}'.format(item))returnTrue
- persistentstorage::使用DefaultStorage,否则每个操作都通过shelve模块存储。
- persistentqueuestorage::使用QueueStorage和PersistentStorage。
# see also the API partfromleakdbimportPersistentQueueStoragestorage=PersistentQueueStorage(filename="/tmp/foobar.db",maxsize=1,workers=1)# the queue is auto-flush, each operations check the queue sizestorage.set('foo',1)
待办事项
- 通过ZeroMQ完成传输层
- 清除代码
- 改进单元测试
- 编写一个cli
- 对每个存储进行基准测试