tarantool知识整理(1)

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值