cpy-leveldb 介绍
cpy-leveldb是在leveldb(google开源的高性能key-
value数据库)的 C API 基础上开发的 python 绑定,目前支持leveldb 的 Put, Get, Delete, Write操作,以及
WriteBatch 的原子更新操作,WriteBatch 还可以通过将多个更新放到同一个 batch
里,在存在大量更新操作时,加速它们的执行,此外,cpy-leveldb 还支持快照(Snapshot),迭代器(Iterator),使 LevelDB
的功能最大化的在 Python 中得到实现。
cpy-python使用例子:
>>> import leveldb >>> db = leveldb.LevelDB("/tmp/leveldb") >>> db.Put("1", "111") >>> db.Put("2", "222") >>> db.Put("3", "333") >>> db.Get("1") '111' >>> db.Get("3") '333' >>> db.Get("2") '222' >>> batch = leveldb.WriteBatch() >>> for i in xrange(20): ... batch.Put(str(i), "hello world %i" % i) ... >>> db.Get("2") '222' >>> db.Get("5") '' >>> db.Write(batch) >>> db.Get("5") 'hello world 5' >>> db.Get("2") 'hello world 2' >>> iter = leveldb.Iterator(db) Iterator_init executed. >>> iter.First() >>> iter.Key() '0' >>> iter.Value() 'hello world 0' >>> iter.Last() >>> iter.Key() '9' >>> iter.Value() 'hello world 9' >>> iter.First() >>> iter.Next() >>> iter.Key() '1' >>> iter.Next() >>> iter.Key() '10' >>> iter.Next() >>> iter.Key() '11' >>> iter.Value() 'hello world 11'
联系作者:[email protected](http://my.oschina.net/forhappy2010)
cpy-leveldb 官网
https://github.com/forhappy/cpy-leveldb
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。