如何使用 python 和 leveldb 遍历所有键

how can I iterate through all keys with python and leveldb

我想使用 python 的 leveldb 绑定来存储数据。我在任何文档中都看不到如何在不提前知道的情况下遍历所有键。我看到在这个页面的 C 绑定中是可能的: https://rawgit.com/google/leveldb/master/doc/index.html

leveldb::Iterator* it = db->NewIterator(leveldb::ReadOptions());
for (it->SeekToFirst(); it->Valid(); it->Next()) {
  cout << it->key().ToString() << ": "  << it->value().ToString() << endl;
}
assert(it->status().ok());  // Check for any errors found during the scan
delete it;

如何从 python 中执行此操作?

如果您正在使用 Plyvel, you can simply do for key, value in db: as per the docs