update
This commit is contained in:
parent
7304c207f6
commit
381bcf92a3
5 changed files with 45 additions and 47 deletions
|
@ -16,16 +16,16 @@ Python bindings to the C++ interface of http://rocksdb.org/ using pybind11::
|
||||||
assert(s.ok())
|
assert(s.ok())
|
||||||
# put
|
# put
|
||||||
opts = pyrocksdb.WriteOptions()
|
opts = pyrocksdb.WriteOptions()
|
||||||
s = db.put(opts, "key1", "value1")
|
s = db.put(opts, b"key1", b"value1")
|
||||||
assert (s.ok())
|
assert (s.ok())
|
||||||
# get
|
# get
|
||||||
opts = pyrocksdb.ReadOptions()
|
opts = pyrocksdb.ReadOptions()
|
||||||
blob = db.get(opts, "key1")
|
blob = db.get(opts, b"key1")
|
||||||
print (blob.data) # value1
|
print (blob.data) # b"value1"
|
||||||
print (blob.status.ok()) # true
|
print (blob.status.ok()) # true
|
||||||
#delete
|
#delete
|
||||||
opts = pyrocksdb.WriteOptions()
|
opts = pyrocksdb.WriteOptions()
|
||||||
s = db.delete(opts, "key1")
|
s = db.delete(opts, b"key1")
|
||||||
assert(s.ok())
|
assert(s.ok())
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@ apply them in a single operation ::
|
||||||
update = pyrocksdb.WriteBatch()
|
update = pyrocksdb.WriteBatch()
|
||||||
|
|
||||||
# collect the operations
|
# collect the operations
|
||||||
update.put('key1', 'value1')
|
update.put(b'key1', b'value1')
|
||||||
update.put('key2', 'value2')
|
update.put(b'key2', b'value2')
|
||||||
update.delete('key1')
|
update.delete(b'key1')
|
||||||
|
|
||||||
opts = pyrocksdb.WriteOptions()
|
opts = pyrocksdb.WriteOptions()
|
||||||
# Apply these operatios in a single operation
|
# Apply these operatios in a single operation
|
||||||
|
@ -20,11 +20,11 @@ apply them in a single operation ::
|
||||||
|
|
||||||
assert s.ok()
|
assert s.ok()
|
||||||
opts = pyrocksdb.ReadOptions()
|
opts = pyrocksdb.ReadOptions()
|
||||||
blob = db.get(opts, 'key1')
|
blob = db.get(opts, b'key1')
|
||||||
assert blob.status.is_not_found()
|
assert blob.status.is_not_found()
|
||||||
blob = db.get(opts, 'key2')
|
blob = db.get(opts, b'key2')
|
||||||
assert blob.status.ok()
|
assert blob.status.ok()
|
||||||
assert blob.data == 'value2'
|
assert blob.data == b'value2'
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
@ -35,36 +35,35 @@ Iterators behave slightly different than expected. Per default they are not
|
||||||
valid. So you have to call one of its seek methods first ::
|
valid. So you have to call one of its seek methods first ::
|
||||||
|
|
||||||
opts = pyrocksdb.WriteOptions()
|
opts = pyrocksdb.WriteOptions()
|
||||||
s = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
|
s = {b'key1': b'value1', b'key2': b'value2', b'key3': b'value3'}
|
||||||
for k, v in s.items():
|
for k, v in s.items():
|
||||||
db.put(opts, k, v)
|
db.put(opts, k, v)
|
||||||
|
|
||||||
opts = pyrocksdb.ReadOptions()
|
opts = pyrocksdb.ReadOptions()
|
||||||
it = db.iterator(opts)
|
it = db.iterator(opts)
|
||||||
# call this first
|
|
||||||
it.seek_to_first()
|
it.seek_to_first()
|
||||||
assert it.status().ok()
|
assert it.status().ok()
|
||||||
assert it.valid()
|
assert it.valid()
|
||||||
for k, v in s.items():
|
for k, v in s.items():
|
||||||
assert it.key().data() == k
|
assert it.key() == k
|
||||||
assert it.value().data() == v
|
assert it.value() == v
|
||||||
it.next()
|
it.next()
|
||||||
|
|
||||||
assert not it.valid()
|
assert not it.valid()
|
||||||
|
|
||||||
it.seek('key1')
|
it.seek(b'key1')
|
||||||
assert it.valid()
|
assert it.valid()
|
||||||
assert it.key().data() == 'key1'
|
assert it.key() == b'key1'
|
||||||
assert it.value().data() == 'value1'
|
assert it.value() == b'value1'
|
||||||
it.seek('key2')
|
it.seek(b'key2')
|
||||||
assert it.valid()
|
assert it.valid()
|
||||||
assert it.key().data() == 'key2'
|
assert it.key() == b'key2'
|
||||||
assert it.value().data() == 'value2'
|
assert it.value() == b'value2'
|
||||||
|
|
||||||
it.seek('key4')
|
it.seek(b'key4')
|
||||||
assert not it.valid()
|
assert not it.valid()
|
||||||
|
|
||||||
it.seek_for_prev('key0')
|
it.seek_for_prev(b'key0')
|
||||||
assert not it.valid()
|
assert not it.valid()
|
||||||
it.seek_for_prev('key4')
|
it.seek_for_prev(b'key4')
|
||||||
assert it.valid()
|
assert it.valid()
|
||||||
|
|
|
@ -47,16 +47,16 @@
|
||||||
<span class="k">assert</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
<span class="k">assert</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||||
<span class="c1"># put</span>
|
<span class="c1"># put</span>
|
||||||
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteOptions</span><span class="p">()</span>
|
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteOptions</span><span class="p">()</span>
|
||||||
<span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="s2">"key1"</span><span class="p">,</span> <span class="s2">"value1"</span><span class="p">)</span>
|
<span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="sa">b</span><span class="s2">"key1"</span><span class="p">,</span> <span class="sa">b</span><span class="s2">"value1"</span><span class="p">)</span>
|
||||||
<span class="k">assert</span> <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
<span class="k">assert</span> <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||||
<span class="c1"># get</span>
|
<span class="c1"># get</span>
|
||||||
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ReadOptions</span><span class="p">()</span>
|
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ReadOptions</span><span class="p">()</span>
|
||||||
<span class="n">blob</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="s2">"key1"</span><span class="p">)</span>
|
<span class="n">blob</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="sa">b</span><span class="s2">"key1"</span><span class="p">)</span>
|
||||||
<span class="nb">print</span> <span class="p">(</span><span class="n">blob</span><span class="o">.</span><span class="n">data</span><span class="p">)</span> <span class="c1"># value1</span>
|
<span class="nb">print</span> <span class="p">(</span><span class="n">blob</span><span class="o">.</span><span class="n">data</span><span class="p">)</span> <span class="c1"># b"value1"</span>
|
||||||
<span class="nb">print</span> <span class="p">(</span><span class="n">blob</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span> <span class="c1"># true</span>
|
<span class="nb">print</span> <span class="p">(</span><span class="n">blob</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span> <span class="c1"># true</span>
|
||||||
<span class="c1">#delete</span>
|
<span class="c1">#delete</span>
|
||||||
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteOptions</span><span class="p">()</span>
|
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteOptions</span><span class="p">()</span>
|
||||||
<span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="s2">"key1"</span><span class="p">)</span>
|
<span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="sa">b</span><span class="s2">"key1"</span><span class="p">)</span>
|
||||||
<span class="k">assert</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
<span class="k">assert</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||||
<span class="n">db</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
<span class="n">db</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Search.setIndex({docnames:["changelog","index","installation","tutorial/index"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.todo":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["changelog.rst","index.rst","installation.rst","tutorial/index.rst"],objects:{},objnames:{},objtypes:{},terms:{"default":[0,3],"import":[0,1],"true":[0,1],Added:0,For:0,With:[],access:0,accord:0,activ:[],add:0,advanc:0,all:0,allow:0,allow_mmap_read:0,allow_mmap_writ:0,also:[0,3],alwai:0,anymor:0,api:0,appli:3,apt:[],argument:0,assert:[1,3],automat:0,avail:0,batch:1,becaus:0,behav:3,bin:[],bind:1,blob:[1,3],block_restart_interv:0,block_siz:0,block_size_devi:0,blockbasedtablefactori:0,bloom_bits_per_kei:0,bloom_bits_per_prefix:0,bottommost_level_compact:0,builder:0,bunch:0,call:[0,3],can:1,change_level:0,changelog:1,clone:2,close:[1,3],code:0,collect:3,com:[0,2],compact:0,compact_rang:0,compaction_options_univers:0,compaction_styl:0,compactrang:0,compressiontyp:0,could:0,creat:1,create_if_miss:1,data:[1,3],databas:0,db_stats_log_interv:0,delet:[1,3],dev:[],dict:0,differ:3,disable_seek_compact:0,distro:[],document:0,drop:0,enabl:0,end:0,ensur:0,expect:3,facebook:0,fals:0,feel:1,first:3,fix:0,follow:0,fork:1,format:0,found:1,free:1,from:[0,1],gather:3,get:[0,1,3],get_properti:0,git:2,github:[0,1,2],have:[0,3],how:[0,1],http:[0,1,2],increaseparallel:1,index:1,init:0,initi:0,instal:1,instruct:1,interfac:1,is_not_found:3,issu:[0,1],item:[0,3],iter:[0,1],iteritem:0,iterkei:0,itertool:0,itervalu:0,its:3,kei:[0,3],key0:3,key1:[1,3],key2:3,key3:3,key4:3,key_may_exist:0,keyword:0,lambda:0,level0_slowdown_writes_trigg:0,level0_stop_writes_trigg:0,librocksdb:[],like:0,list:0,lrucach:0,lz4_compress:0,lz4hc_compress:0,make:0,max_background_flush:0,max_open_fil:0,mean:0,memori:0,memtabl:0,memtable_factori:0,method:3,modif:3,modul:1,more:0,move:0,multi:1,multi_get:0,name:0,need:0,newer:0,newtotalorderplaintablefactori:0,next:3,no_block_cach:0,now:0,one:3,onli:0,open:1,oper:3,operatio:3,opt:[1,3],optim:0,optimizelevelstylecompact:1,option:[0,1],org:1,own:0,packag:[],page:[0,1],paramet:0,paranoid_check:0,path:1,per:3,persist:0,pip:[],plaintabl:0,plaintablefactori:0,pointer:0,possibl:[0,3],prefix:0,prefix_extractor:0,prefix_seek:0,print:[0,1],properti:0,publish:0,pull:1,put:[1,3],pybind11:[1,2],pypi:0,pyrocksdb:[0,1,3],python3:1,raw:0,readopt:[0,1,3],realiz:0,recurs:2,reduce_level:0,relat:0,remov:0,renam:0,repair_db:0,represent:0,request:1,requir:[],rm_scan_count_limit:0,rocksdb:0,row_cach:0,search:1,seek:[0,3],seek_for_prev:3,seek_to_first:3,self:0,send:1,set:0,setup:2,singl:3,slightli:3,smart:0,solut:0,sourc:1,sst:0,stai:0,startswith:0,statu:[1,3],style:0,support:0,tabl:0,table_cache_remove_scan_count_limit:0,table_factori:0,takewhil:0,test:1,than:3,thei:3,them:3,thi:[0,3],thread:1,too:0,tracker:1,tutori:1,twmht:2,univers:0,updat:[0,3],use:0,uses:0,using:1,valid:3,valu:[0,3],value1:[1,3],value2:3,value3:3,venv:[],verify_checksums_in_compact:0,version:1,virtualenv:[],walk:0,were:0,which:0,whole_key_filt:0,wiki:0,within:0,work:0,write:[0,3],writebatch:3,writebatchiter:0,writeopt:[1,3],wrtie:1,you:[0,3],your:0},titles:["Changelog","Welcome to python-rocksdb\u2019s documentation!","Installing","Basic Usage of python-rocksdb"],titleterms:{"new":0,With:[],backward:0,basic:3,batch:3,build:2,chang:0,changelog:0,contribut:1,distro:[],document:1,from:2,incompat:0,indic:1,instal:2,iter:3,overview:1,packag:[],pypi:[],python:[1,2,3],rocksdb:[1,2,3],sourc:2,tabl:1,usag:3,version:0,welcom:1,wrtie:3}})
|
Search.setIndex({docnames:["changelog","index","installation","tutorial/index"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.todo":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["changelog.rst","index.rst","installation.rst","tutorial/index.rst"],objects:{},objnames:{},objtypes:{},terms:{"default":[0,3],"import":[0,1],"true":[0,1],Added:0,For:0,With:[],access:0,accord:0,activ:[],add:0,advanc:0,all:0,allow:0,allow_mmap_read:0,allow_mmap_writ:0,also:[0,3],alwai:0,anymor:0,api:0,appli:3,apt:[],argument:0,assert:[1,3],automat:0,avail:0,batch:1,becaus:0,behav:3,bin:[],bind:1,blob:[1,3],block_restart_interv:0,block_siz:0,block_size_devi:0,blockbasedtablefactori:0,bloom_bits_per_kei:0,bloom_bits_per_prefix:0,bottommost_level_compact:0,builder:0,bunch:0,call:[0,3],can:1,change_level:0,changelog:1,clone:2,close:[1,3],code:0,collect:3,com:[0,2],compact:0,compact_rang:0,compaction_options_univers:0,compaction_styl:0,compactrang:0,compressiontyp:0,could:0,creat:1,create_if_miss:1,data:[1,3],databas:0,db_stats_log_interv:0,delet:[1,3],dev:[],dict:0,differ:3,disable_seek_compact:0,distro:[],document:0,drop:0,enabl:0,end:0,ensur:0,expect:3,facebook:0,fals:0,feel:1,first:3,fix:0,follow:0,fork:1,format:0,found:1,free:1,from:[0,1],gather:3,get:[0,1,3],get_properti:0,git:2,github:[0,1,2],have:[0,3],how:[0,1],http:[0,1,2],increaseparallel:1,index:1,init:0,initi:0,instal:1,instruct:1,interfac:1,is_not_found:3,issu:[0,1],item:[0,3],iter:[0,1],iteritem:0,iterkei:0,itertool:0,itervalu:0,its:3,kei:[0,3],key0:3,key1:[1,3],key2:3,key3:3,key4:3,key_may_exist:0,keyword:0,lambda:0,level0_slowdown_writes_trigg:0,level0_stop_writes_trigg:0,librocksdb:[],like:0,list:0,lrucach:0,lz4_compress:0,lz4hc_compress:0,make:0,max_background_flush:0,max_open_fil:0,mean:0,memori:0,memtabl:0,memtable_factori:0,method:3,modif:3,modul:1,more:0,move:0,multi:1,multi_get:0,name:0,need:0,newer:0,newtotalorderplaintablefactori:0,next:3,no_block_cach:0,now:0,one:3,onli:0,open:1,oper:3,operatio:3,opt:[1,3],optim:0,optimizelevelstylecompact:1,option:[0,1],org:1,own:0,packag:[],page:[0,1],paramet:0,paranoid_check:0,path:1,per:3,persist:0,pip:[],plaintabl:0,plaintablefactori:0,pointer:0,possibl:[0,3],prefix:0,prefix_extractor:0,prefix_seek:0,print:[0,1],properti:0,publish:0,pull:1,put:[1,3],pybind11:[1,2],pypi:0,pyrocksdb:[0,1,3],python3:1,raw:0,readopt:[0,1,3],realiz:0,recurs:2,reduce_level:0,relat:0,remov:0,renam:0,repair_db:0,represent:0,request:1,requir:[],rm_scan_count_limit:0,rocksdb:0,row_cach:0,search:1,seek:[0,3],seek_for_prev:3,seek_to_first:3,self:0,send:1,set:0,setup:2,singl:3,slightli:3,smart:0,solut:0,sourc:1,sst:0,stai:0,startswith:0,statu:[1,3],style:0,support:0,tabl:0,table_cache_remove_scan_count_limit:0,table_factori:0,takewhil:0,test:1,than:3,thei:3,them:3,thi:0,thread:1,too:0,tracker:1,tutori:1,twmht:2,univers:0,updat:[0,3],use:0,uses:0,using:1,valid:3,valu:[0,3],value1:[1,3],value2:3,value3:3,venv:[],verify_checksums_in_compact:0,version:1,virtualenv:[],walk:0,were:0,which:0,whole_key_filt:0,wiki:0,within:0,work:0,write:[0,3],writebatch:3,writebatchiter:0,writeopt:[1,3],wrtie:1,you:[0,3],your:0},titles:["Changelog","Welcome to python-rocksdb\u2019s documentation!","Installing","Basic Usage of python-rocksdb"],titleterms:{"new":0,With:[],backward:0,basic:3,batch:3,build:2,chang:0,changelog:0,contribut:1,distro:[],document:1,from:2,incompat:0,indic:1,instal:2,iter:3,overview:1,packag:[],pypi:[],python:[1,2,3],rocksdb:[1,2,3],sourc:2,tabl:1,usag:3,version:0,welcom:1,wrtie:3}})
|
|
@ -41,9 +41,9 @@ apply them in a single operation</p>
|
||||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">update</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteBatch</span><span class="p">()</span>
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">update</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteBatch</span><span class="p">()</span>
|
||||||
|
|
||||||
<span class="c1"># collect the operations</span>
|
<span class="c1"># collect the operations</span>
|
||||||
<span class="n">update</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="s1">'key1'</span><span class="p">,</span> <span class="s1">'value1'</span><span class="p">)</span>
|
<span class="n">update</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="sa">b</span><span class="s1">'key1'</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'value1'</span><span class="p">)</span>
|
||||||
<span class="n">update</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="s1">'key2'</span><span class="p">,</span> <span class="s1">'value2'</span><span class="p">)</span>
|
<span class="n">update</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="sa">b</span><span class="s1">'key2'</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'value2'</span><span class="p">)</span>
|
||||||
<span class="n">update</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="s1">'key1'</span><span class="p">)</span>
|
<span class="n">update</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="sa">b</span><span class="s1">'key1'</span><span class="p">)</span>
|
||||||
|
|
||||||
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteOptions</span><span class="p">()</span>
|
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteOptions</span><span class="p">()</span>
|
||||||
<span class="c1"># Apply these operatios in a single operation</span>
|
<span class="c1"># Apply these operatios in a single operation</span>
|
||||||
|
@ -51,11 +51,11 @@ apply them in a single operation</p>
|
||||||
|
|
||||||
<span class="k">assert</span> <span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">()</span>
|
||||||
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ReadOptions</span><span class="p">()</span>
|
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ReadOptions</span><span class="p">()</span>
|
||||||
<span class="n">blob</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="s1">'key1'</span><span class="p">)</span>
|
<span class="n">blob</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'key1'</span><span class="p">)</span>
|
||||||
<span class="k">assert</span> <span class="n">blob</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">is_not_found</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="n">blob</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">is_not_found</span><span class="p">()</span>
|
||||||
<span class="n">blob</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="s1">'key2'</span><span class="p">)</span>
|
<span class="n">blob</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'key2'</span><span class="p">)</span>
|
||||||
<span class="k">assert</span> <span class="n">blob</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">ok</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="n">blob</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">ok</span><span class="p">()</span>
|
||||||
<span class="k">assert</span> <span class="n">blob</span><span class="o">.</span><span class="n">data</span> <span class="o">==</span> <span class="s1">'value2'</span>
|
<span class="k">assert</span> <span class="n">blob</span><span class="o">.</span><span class="n">data</span> <span class="o">==</span> <span class="sa">b</span><span class="s1">'value2'</span>
|
||||||
|
|
||||||
<span class="n">db</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
<span class="n">db</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
@ -66,38 +66,37 @@ apply them in a single operation</p>
|
||||||
<p>Iterators behave slightly different than expected. Per default they are not
|
<p>Iterators behave slightly different than expected. Per default they are not
|
||||||
valid. So you have to call one of its seek methods first</p>
|
valid. So you have to call one of its seek methods first</p>
|
||||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteOptions</span><span class="p">()</span>
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteOptions</span><span class="p">()</span>
|
||||||
<span class="n">s</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'key1'</span><span class="p">:</span> <span class="s1">'value1'</span><span class="p">,</span> <span class="s1">'key2'</span><span class="p">:</span> <span class="s1">'value2'</span><span class="p">,</span> <span class="s1">'key3'</span><span class="p">:</span> <span class="s1">'value3'</span><span class="p">}</span>
|
<span class="n">s</span> <span class="o">=</span> <span class="p">{</span><span class="sa">b</span><span class="s1">'key1'</span><span class="p">:</span> <span class="sa">b</span><span class="s1">'value1'</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'key2'</span><span class="p">:</span> <span class="sa">b</span><span class="s1">'value2'</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'key3'</span><span class="p">:</span> <span class="sa">b</span><span class="s1">'value3'</span><span class="p">}</span>
|
||||||
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
|
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
|
||||||
<span class="n">db</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
|
<span class="n">db</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
|
||||||
|
|
||||||
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ReadOptions</span><span class="p">()</span>
|
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ReadOptions</span><span class="p">()</span>
|
||||||
<span class="n">it</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">iterator</span><span class="p">(</span><span class="n">opts</span><span class="p">)</span>
|
<span class="n">it</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">iterator</span><span class="p">(</span><span class="n">opts</span><span class="p">)</span>
|
||||||
<span class="c1"># call this first</span>
|
|
||||||
<span class="n">it</span><span class="o">.</span><span class="n">seek_to_first</span><span class="p">()</span>
|
<span class="n">it</span><span class="o">.</span><span class="n">seek_to_first</span><span class="p">()</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">status</span><span class="p">()</span><span class="o">.</span><span class="n">ok</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">status</span><span class="p">()</span><span class="o">.</span><span class="n">ok</span><span class="p">()</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
||||||
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
|
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">key</span><span class="p">()</span><span class="o">.</span><span class="n">data</span><span class="p">()</span> <span class="o">==</span> <span class="n">k</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">key</span><span class="p">()</span> <span class="o">==</span> <span class="n">k</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">value</span><span class="p">()</span><span class="o">.</span><span class="n">data</span><span class="p">()</span> <span class="o">==</span> <span class="n">v</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">value</span><span class="p">()</span> <span class="o">==</span> <span class="n">v</span>
|
||||||
<span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
|
<span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
|
||||||
|
|
||||||
<span class="k">assert</span> <span class="ow">not</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="ow">not</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
||||||
|
|
||||||
<span class="n">it</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="s1">'key1'</span><span class="p">)</span>
|
<span class="n">it</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="sa">b</span><span class="s1">'key1'</span><span class="p">)</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">key</span><span class="p">()</span><span class="o">.</span><span class="n">data</span><span class="p">()</span> <span class="o">==</span> <span class="s1">'key1'</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">key</span><span class="p">()</span> <span class="o">==</span> <span class="sa">b</span><span class="s1">'key1'</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">value</span><span class="p">()</span><span class="o">.</span><span class="n">data</span><span class="p">()</span> <span class="o">==</span> <span class="s1">'value1'</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">value</span><span class="p">()</span> <span class="o">==</span> <span class="sa">b</span><span class="s1">'value1'</span>
|
||||||
<span class="n">it</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="s1">'key2'</span><span class="p">)</span>
|
<span class="n">it</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="sa">b</span><span class="s1">'key2'</span><span class="p">)</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">key</span><span class="p">()</span><span class="o">.</span><span class="n">data</span><span class="p">()</span> <span class="o">==</span> <span class="s1">'key2'</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">key</span><span class="p">()</span> <span class="o">==</span> <span class="sa">b</span><span class="s1">'key2'</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">value</span><span class="p">()</span><span class="o">.</span><span class="n">data</span><span class="p">()</span> <span class="o">==</span> <span class="s1">'value2'</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">value</span><span class="p">()</span> <span class="o">==</span> <span class="sa">b</span><span class="s1">'value2'</span>
|
||||||
|
|
||||||
<span class="n">it</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="s1">'key4'</span><span class="p">)</span>
|
<span class="n">it</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="sa">b</span><span class="s1">'key4'</span><span class="p">)</span>
|
||||||
<span class="k">assert</span> <span class="ow">not</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="ow">not</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
||||||
|
|
||||||
<span class="n">it</span><span class="o">.</span><span class="n">seek_for_prev</span><span class="p">(</span><span class="s1">'key0'</span><span class="p">)</span>
|
<span class="n">it</span><span class="o">.</span><span class="n">seek_for_prev</span><span class="p">(</span><span class="sa">b</span><span class="s1">'key0'</span><span class="p">)</span>
|
||||||
<span class="k">assert</span> <span class="ow">not</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="ow">not</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
||||||
<span class="n">it</span><span class="o">.</span><span class="n">seek_for_prev</span><span class="p">(</span><span class="s1">'key4'</span><span class="p">)</span>
|
<span class="n">it</span><span class="o">.</span><span class="n">seek_for_prev</span><span class="p">(</span><span class="sa">b</span><span class="s1">'key4'</span><span class="p">)</span>
|
||||||
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
<span class="k">assert</span> <span class="n">it</span><span class="o">.</span><span class="n">valid</span><span class="p">()</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue