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技術的優質平台!