The fastest lua client for ssdb and nginx (based on lua-nginx-module).
- Nodejs ssdb client: https://github.com/eleme/node-ssdb
- Python ssdb client: https://github.com/hit9/ssdb.py
v0.0.4
Build and copy directory resty
to your nginx's lua path:
$ git clone https://github.com/eleme/lua-resty-ssdb path/to/nginx/lua/resty/ssdb
$ cd path/to/nginx/lua/lua/resty/ssdb
$ git submodule update --init
$ make
lua path
and lua cpath
should be configured in your nginx conf like this:
lua_package_path 'path/to/nginx/lua/?.lua;';
lua_package_cpath 'path/to/nginx/lua/?.so;';
local ssdb = require('resty.ssdb.client')
local client = ssdb.newclient()
local res, err = client:set('k', 'v')
local res, err = client:get('k')
client:start_pipeline()
client:set('k1', 'v1')
client:set('k2', 'v2')
client:set('k3', 'v3')
vals = client:commit_pipeline()
err
is notnil
on any errors.res
isnil
on any errors.
Values returned from commands can be found from
table commands
in ssdb.lua.
All possible err
values for all ssdb commands:
'ok', 'not_found', 'server_error', 'client_error', 'timeout', 'connection refused'
To create a ssdb client:
local ssdb = require 'resty.ssdb.client'
local client = ssdb.newclient()
options (with default values):
{
host = '127.0.0.1',
port = 8888,
auth = nil, -- lazy auto authed
timeout = 0
}
Close from ssdb server.
Start pipeline.
Commit pipeline to ssdb server, return table of multiple vals like {res, err}
.
Cancel current pipeline.
See tcpsock:setkeepalive.
setkeepalive
can be used to make a long connection, e.g., a forever long long connection:
client:setkeepalive(0, 1)
By default, ssdb is lazy connected, but method connect
can be used to
test if the server is alive, e.g.
ok, err = client.connect()
if not ok then
ngx.log(ngx.ERR, err)
return
end
Detail docs for ssdb commands can be found at https://github.com/hit9/ssdb.api.docs.
MIT, Copyright (c) 2015 Eleme, Inc. Detail see LICENSE-MIT