Example:
# First you need to start a ttserver, example command (starting a
# server on default address localhost:1978): ttserver test.tct
# see http://fallabs.com/tokyotyrant/spex.html#serverprog and
# http://fallabs.com/tokyotyrant/spex.html#tutorial for more info
# about ttserver
from tokyo.tyrant import *
rtdb = RTDB()
# if need be, you should call tune before open, ex. with default values:
rtdb.tune(0, 0)
# open the database
rtdb.open() # this will open the server at localhost:1978
# store records
for key, value in [
("foo", {"age": "30", "name": "John", "sex": "m"}),
("bar", {"age": "56", "name": "Paul", "sex": "m"}),
("baz", {"age": "22", "name": "Ella", "sex": "f"})
]:
rtdb[key] = value
# retrieve one record
print(rtdb["foo"])
# traverse records
for key in rtdb:
print(key, rtdb[key])
# close the database
rtdb.close()
Warning
This client works only with Tokyo Tyrant daemon serving table databases.
Note
For all methods taking either a key argument or a pair (key, value), key must be either str (Python2) or bytes (Python3) and value must be a dict.
All items in value must be pairs of str (Python2) or bytes (Python3). Empty keys in value are not allowed.
See also
Tune a database.
Parameters: |
|
---|
Note
Tuning an open database is an invalid operation.
Open a database.
Parameters: |
|
---|
Close the database.
Note
RTDBs are closed when garbage-collected.
Copy the database file.
Parameter: | path – path to the destination file. This path refers to the server, not the client, the database is not copied locally. |
---|
Return an iterator over the database’s keys.
New in version 0.6.1.
Return an iterator over the database’s values.
New in version 0.6.1.
Return an iterator over the database’s items ((key, value) pairs).
New in version 0.6.1.
Return an iterator over the database’s values’ keys.
New in version 0.6.1.
Return an iterator over the database’s values’ values.
New in version 0.6.1.
Restore a database from an update log.
Parameters: |
|
---|
Set the replication master of a database.
Parameters: |
|
---|
Add an index to a column.
Parameters: |
|
---|
Combine queries and return the result set as a tuple of keys.
Parameters: |
|
---|
Optimize a database. This method only accepts keyword arguments. Each argument must be a str (Python2) or bytes (Python3) representation of its real value. See tokyo.cabinet.TDB.optimize() for valid arguments and values. Example:
rtdb.optimize(bnum='0', apow='-1', fpow='-1', opts='255')
Note
Optimizing a read only database is an invalid operation.
When first returned by RTDB.query() a query result set potentially includes all keys contained in the database. You can narrow down a search by calling filter() and limit the number of results with limit().
Filter the result set on the condition expressed by the parameters.
Parameters: |
|
---|
Note
Calling filter() multiple times with different conditions is equivalent to applying a logical AND between the conditions.
Unfortunately, due to a Tokyo Tyrant limitation, neither column nor expr can contain null bytes.
Sort the result set.
Parameters: |
|
---|
Note
Unfortunately, due to a Tokyo Tyrant limitation, column cannot contain null bytes.
Limit the number of keys in the result set.
Parameters: |
|
---|