def close(self): return HDB.close(self)
#!/usr/bin/python # # This code is based upon example.pl from the Perl TokyoCabinet API. # import sys from pytc import HDB, HDBOWRITER, HDBOCREAT hdb = HDB() # Open a hashdb for writing if it exists, or create a new one # This database is uncompressed. See hashdb.create for example of compression. hdb.open("casket.tch", HDBOWRITER | HDBOCREAT) # store records hdb.put("foo", "hop") hdb.put("bar", "step") hdb.put("baz", "jump") # retrieve records print hdb.get("foo") # traverse records hdb.iterinit() for key in hdb.keys(): print "%s:%s" % (key, hdb.get(key)) # close the database hdb.close()
def put(self, key, value): return HDB.put(self, key, common.json.dumps(value))
def values(self): return [common.json.loads(v) for v in HDB.values(self)]
def __setitem__(self, key, value): return HDB.__setitem__(self, key, common.json.dumps(value))
def get(self, key): return common.json.loads(HDB.get(self, key))
def __getitem__(self, key): return common.json.loads(HDB.__getitem__(self, key))