-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.lua
More file actions
46 lines (32 loc) · 810 Bytes
/
example.lua
File metadata and controls
46 lines (32 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
LevelDB = require 'leveldb'
db = LevelDB.new('./tmp')
print('version: ' .. db.version .. "\n")
print('Get k1 => ' .. (db:get('k1') or "'nil'"))
print('Get k2 => ' .. (db:get('k2') or "'nil'"))
print('Get unset_key => ' .. (db:get('unset_key') or "'nil'"))
print("")
function print_db_data()
print('Iterator all keys')
db:each(nil, function(k, v) print(k, v) end)
print("")
end
print("Set k3")
db:set('k3', tostring(os.time()))
print("")
print("Batch set k1 k2 k4 k5")
db:batchSet({k1 = tostring(os.time()), k2 = '321321', k4 = '111', k5 = '222'})
print("")
print_db_data()
print("Del k3")
db:del('k3')
print("")
print_db_data()
print("Batch del k4, k5")
db:batchDel({'k4', 'k5'})
print("")
print_db_data()
print('close')
db:close()
print('destory')
LevelDB.destroy_db('./tmp')
print('end')