Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chexiongsheng/luavkv
lua key-value store with version number
https://github.com/chexiongsheng/luavkv
Last synced: 11 days ago
JSON representation
lua key-value store with version number
- Host: GitHub
- URL: https://github.com/chexiongsheng/luavkv
- Owner: chexiongsheng
- Created: 2014-05-07T08:33:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-05-20T09:57:17.000Z (over 10 years ago)
- Last Synced: 2024-10-11T09:54:13.319Z (about 1 month ago)
- Language: Lua
- Homepage:
- Size: 273 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
luavkv
======key-value store with version number
## Usage
### Basics
```lua
local vkv = require 'vkv'
local key = 12345
print(vkv.existed(key)) --false
--init a value, paramters: version-key-value, that is why this lib named vkv
print(vkv.put(1, key, {b = {c = 1111}, [5] = 1})) -- true
print(vkv.existed(key)) --true
-- get two copy
local c1 = vkv.get_copy(key)
local c2 = vkv.get_copy(key)
c1.d = 1000
c2.d = 2000
print(vkv.set(key, c2)) --true
--the copy c1 is out of date, so fail to update to the vkv
print(vkv.set(key, c1)) --false
--the api set_test can test if a copy can commit
print(vkv.set_test(key, c1)) --false
local c3 = vkv.get_copy(key)
print(c3.d) -- 2000
print(vkv.version_of(key)) --2
print(vkv.version_of(c3)) --3
```### Intercept the table functions
```lua
local vkv = require 'vkv'
local key = 12345
vkv.put(1, key, {b = {c = 1111}, [5] = 1}) -- truelocal c = vkv.get_copy(key)
for k in pairs(c) do
print(k)
end
--output:
-- __target_objvkv.intercept_G() --make pairs, ipairs, next, table.each etc. intercepted
for k in pairs(c) do
print(k)
end
--output:
-- b
-- 5
```