[关闭]
@bergus 2017-02-22T07:07:02.000000Z 字数 2569 阅读 1539

python leveldb 文档

python leveldb


  1. import leveldb
  2. db = leveldb.LevelDB('./db')
  3. db.Put('hello', 'world')
  4. print db.Get('hello')
  5. db.Delete('hello')
  6. print db.Get('hello')
  7. batch = leveldb.WriteBatch()
  8. batch.Put('hello', 'world')
  9. batch.Put('hello again', 'world')
  10. batch.Delete('hello')
  11. db.Write(batch, sync = True)
  1. class LevelDB(builtin.object) | LevelDB(filename, **kwargs) -> leveldb object |
  2. | Open a LevelDB database, from the given directory. |
  3. | Only the parameter filename is mandatory. |
  4. | filename the database directory | create_if_missing (default: True) if True, creates a new database if none exists | error_if_exists (default: False) if True, raises and error if the database already exists | paranoid_checks (default: False) if True, raises an error as soon as an internal corruption is detected | block_cache_size (default: 8 * (2 << 20)) maximum allowed size for the block cache in bytes | write_buffer_size (default 2 * (2 << 20))
  5. | block_size (default: 4096) unit of transfer for the block cache in bytes | max_open_files: (default: 1000) | block_restart_interval
  6. |
  7. | Snappy compression is used, if available. |
  8. | Some methods support the following parameters, having these semantics: |
  9. | verify_checksum: iff True, the operation will check for checksum mismatches | fill_cache: iff True, the operation will fill the cache with the data read | sync: iff True, the operation will be guaranteed to sync the operation to disk |
  10. | Methods supported are: |
  11. | Get(key, verify_checksums = False, fill_cache = True): get value, raises KeyError if key not found |
  12. | key: the query key |
  13. | Put(key, value, sync = False): put key/value pair |
  14. | key: the key | value: the value |
  15. | Delete(key, sync = False): delete key/value pair, raises no error kf key not found |
  16. | key: the key |
  17. | Write(write_batch, sync = False): apply multiple put/delete operations atomatically |
  18. | write_batch: the WriteBatch object holding the operations |
  19. | RangeIter(key_from = None, key_to = None, include_value = True, verify_checksums = False, fill_cache = True): return iterator |
  20. | key_from: if not None: defines lower bound (inclusive) for iterator | key_to: if not None: defined upper bound (inclusive) for iterator | include_value: if True, iterator returns key/value 2-tuples, otherwise, just keys |
  21. | GetStats(): get a string of runtime information
  1. class WriteBatch(builtin.object) | WriteBatch() -> write batch object |
  2. | Create an object, which can hold a list of database operations, which | can be applied atomically. |
  3. | Methods supported are: |
  4. | Put(key, value): add put operation to batch |
  5. | key: the key | value: the value |
  6. | Delete(key): add delete operation to batch |
  7. | key: the key |
  1. 'CompactRange',
  2. 'CreateSnapshot',
  3. 'Delete',
  4. 'Get',
  5. 'GetStats',
  6. 'Put',
  7. 'RangeIter',//通过Key进行切片处理,因为所有的存储都是有序的
  8. 'Write',
  9. '__class__',
  10. '__delattr__',
  11. '__doc__',
  12. '__format__',
  13. '__getattribute__',
  14. '__hash__',
  15. '__init__',
  16. '__new__',
  17. '__reduce__',
  18. '__reduce_ex__',
  19. '__repr__',
  20. '__setattr__',
  21. '__sizeof__',
  22. '__str__',
  23. '__subclasshook__']
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注