admin
admin
6661 0 0

leveldb + python 的数据库方案

LevelDB是google开源的一个key-value存储引擎库,LevelDB采用日志式的写方式来提高写性能,但是牺牲了部分读性能。为了弥补牺牲了的读性能,一些人提议使用SSD作为存储介质。

LevelDB提供了Put,Delete和Get三个方法对数据库进行修改和查询。

py-leveldb 示例

import leveldb

db = leveldb.LevelDB('./db')

# single put
db.Put('hello', 'world')
print db.Get('hello')

# single delete
db.Delete('hello')
print db.Get('hello')

# multiple put/delete applied atomically, and committed to disk
batch = leveldb.WriteBatch()
batch.Put('hello', 'world')
batch.Put('hello again', 'world')
batch.Delete('hello')

db.Write(batch, sync = True)
0

See Also

Nearby


Discussion

Login Topics