tarantool
是一个高性能的key/value存储服务器,“Get your data in RAM. Get compute close to data. Enjoy the performance”这是官网的解释。
安装:
yum install tarantool
启动:
1.tarantool /path/script.lua
2.tarantoolctl start/stop/enter/restart /etc/tarantool/test.available –可以通过help来具体的看看每个参数是什么意思
注意:script.lua和test.available文件内容相同,内容见实例。
3.通过tarantool进入命令行模式
1.box.space.hosts:select{“1.1.1.1”}
2.box.space.hosts:insert{“1.1.1.1”, “hello world”, 1}
3.box.space.hosts:update({“1.1.1.1”}, {“=“, 2, “value2”})
4.box.space.hosts:replace{“1.1.1.1”, “dummy”, 1111}
5.box.space.hosts:delete{“1.1.1.1”}
4.openresty的库 https://github.com/perusio/lua-resty-tarantool
实例:
app.lua
#!/usr/bin/env tarantool
box.cfg {
listen = 3301,
logger =”tarantool.log”,
log_level = 5,
logger_nonblock=true,
background = true, –后台运行
pid_file = “tarantool.pid”,
wal_mode = “none”,
}
local function create_space()
box.schema.user.create(‘demo’, {password=’123456’}) –创建客户端连接用户
box.schema.user.grant(‘demo’, ‘read,write,execute’, ‘universe’) –客户端连接用户的权限
box.schema.space.create(‘hosts’) – 类似于表
box.space.hosts:create_index(‘primary’, {type = ‘hash’, parts = {1, ‘STR’}}) – 索引
end
box.once(‘schema’, create_space)
function hello(name)
return “hello ” .. name
end
function get(key)
return box.space.hosts:select(key)
end
client.py
#!/usr/bin/python
c = Connection(“127.0.0.1”, 3301, “demo”, “123456”)
result = c.insert(“hosts”, (“1.1.1.1”, “hello 1”))
print result
result = c.call(‘hello’, “dummy”)
print result
result = c.call(‘get’, “1.1.1.1”)
print result