New in version 0.1.2.
Parameter: | bnum – the number of elements in a bucket array. If omitted or specified as 0, the default value (65536) is used. |
---|
Example:
from tokyocabinet import *
mdb = MDB()
# store records
for key, value in [("foo", "hop"), ("bar", "step"), ("baz", "jump")]:
mdb[key] = value
# retrieve one record
print(mdb["foo"])
# traverse records
for key in mdb:
print(key, mdb[key])
Note
For all methods taking either a key argument or a pair (key, value), key and value must be either str (Python2) or bytes (Python3).
See also
Return the value corresponding to key. Equivalent to mdb[key].
New in version 0.2.0.
Delete a record from the database. Equivalent to del mdb[key].
New in version 0.2.0.
Methods keys(), values() and items() are not yet implemented (mainly because I didn’t settle on how to do it: should they return Iterable, Iterator, MappingView, etc.?). Any help would be greatly appreciated in this matter.
For the time being, for those of you who really need these methods, it’s trivial to implement them in python. Here is an example using generators:
from tokyocabinet import MDB as _MDB
class MDB(_MDB):
def keys(self):
return (key for key in self)
def values(self):
return (self[key] for key in self)
def items(self):
return ((key, self[key]) for key in self)