leveldb_test.py 755 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. __author__ = "ZhenQin"
  4. import os, stat
  5. import os.path as path
  6. from datetime import datetime
  7. import shutil
  8. import logging
  9. import sys
  10. import leveldb
  11. db = leveldb.LevelDB('./db')
  12. db.Put('hello'.encode("UTF-8"), 'world'.encode("UTF-8"))
  13. print(db.Get('hello'.encode("UTF-8")).decode("UTF-8"))
  14. batch = leveldb.WriteBatch()
  15. batch.Put('hello'.encode("UTF-8"), 'world'.encode("UTF-8"))
  16. batch.Put('hello again'.encode("UTF-8"), 'world'.encode("UTF-8"))
  17. # batch.Delete('hello'.encode("UTF-8"))
  18. for i in range(1, 100000):
  19. key = "hello_" + str(i)
  20. val = "world_" + str(i)
  21. batch.Put(key.encode("UTF-8"), val.encode("UTF-8"))
  22. db.Write(batch, sync = True)
  23. # db.close()
  24. if __name__ == "__main__":
  25. pass