现在的位置: 首页 > 数据库 > 正文

cpy-leveldb功能怎么才能在Python 中得到实现

2020年07月02日 数据库 ⁄ 共 1070字 ⁄ 字号 评论关闭

  cpy-leveldb是在leveldb(google开源的高性能key-value数据库)的CAPI基础上开发的python绑定,目前支持leveldb的Put,Get,Delete,Write操作,以及WriteBatch的原子更新操作。下面学步园小编来讲解下cpy-leveldb功能怎么才能在Python中得到实现?

  cpy-leveldb功能怎么才能在Python中得到实现

  >>>importleveldb

  >>>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()

  >>>foriinxrange(20):

  ...batch.Put(str(i),"helloworld%i"%i)

  ...

  cpy-leveldb功能怎么才能在Python中得到实现

  >>>db.Get("2")

  '222'

  >>>db.Get("5")

  ''

  >>>db.Write(batch)

  >>>db.Get("5")

  'helloworld5'

  >>>db.Get("2")

  'helloworld2'

  >>>iter=leveldb.Iterator(db)

  Iterator_initexecuted.

  >>>iter.First()

  >>>iter.Key()

  '0'

  >>>iter.Value()

  'helloworld0'

  >>>iter.Last()

  >>>iter.Key()

  '9'

  >>>iter.Value()

  'helloworld9'

  >>>iter.First()

  >>>iter.Next()

  >>>iter.Key()

  '1'

  >>>iter.Next()

  >>>iter.Key()

  '10'

  >>>iter.Next()

  >>>iter.Key()

  '11'

  >>>iter.Value()

  'helloworld11'

  以上就是关于“cpy-leveldb功能怎么才能在Python中得到实现”的内容,希望对大家有用。更多资讯请关注学步园。学步园,您学习IT技术的优质平台!

抱歉!评论已关闭.