123456789101112131415161718192021222324252627282930313233 |
- #!/usr/bin/env python
- # -*- coding:utf-8 -*-
- __author__ = "ZhenQin"
- import os, stat
- import os.path as path
- from datetime import datetime
- import shutil
- import logging
- import sys
- import leveldb
- db = leveldb.LevelDB('./db')
- db.Put('hello'.encode("UTF-8"), 'world'.encode("UTF-8"))
- print(db.Get('hello'.encode("UTF-8")).decode("UTF-8"))
- batch = leveldb.WriteBatch()
- batch.Put('hello'.encode("UTF-8"), 'world'.encode("UTF-8"))
- batch.Put('hello again'.encode("UTF-8"), 'world'.encode("UTF-8"))
- # batch.Delete('hello'.encode("UTF-8"))
- for i in range(1, 100000):
- key = "hello_" + str(i)
- val = "world_" + str(i)
- batch.Put(key.encode("UTF-8"), val.encode("UTF-8"))
- db.Write(batch, sync = True)
- # db.close()
- if __name__ == "__main__":
- pass
|