Giter Site home page Giter Site logo

lua-resty-ssdb's Introduction

lua-resty-ssdb

The fastest lua client for ssdb and nginx (based on lua-nginx-module).

Ports

Version

v0.0.2

Usage

Build and copy directory resty to your nginx's lua path:

$ cd path/to/lua-resty-ssdb
$ make
$ cp -r path/to/lua-resty-ssdb/lib/resty path/to/nginx/lua

lua path and lua cpath should be configured in your nginx conf like this:

lua_package_path 'path/to/lua/?.lua;';
lua_package_cpath 'path/to/lua/?.so;';

API Reference

Sample Usage

local ssdb = require('resty.ssdb.client')
local client = ssdb.newclient()
local res, err = client:set('k', 'v')
local res, err = client:get('k')

Pipeline

client:start_pipeline()
client:set('k1', 'v1')
client:set('k2', 'v2')
client:set('k3', 'v3')
vals = client:commit_pipeline()

Returns

  • err is not nil on any errors.
  • res is nil on any errors.

Value Types

Values returned from commands can be found from table commands in ssdb.lua.

Errors

All possible err values for all ssdb commands:

'ok', 'not_found', 'server_error', 'client_error', 'timeout', 'connection refused'

newclient(options)

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
}

client:close()

Close from ssdb server.

client:start_pipeline()

Start pipeline.

client:commit_pipeline()

Commit pipeline to ssdb server, return table of multiple vals like {res, err}.

client:cancel_pipeline()

Cancel current pipeline.

client:setkeepalive(timeout, size)

See tcpsock:setkeepalive.

setkeepalive can be used to make a long connection, e.g., a forever long long connection:

client:setkeepalive(0, 1)

client:connect()

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

Documentations

Detail docs for ssdb commands can be found at https://github.com/hit9/ssdb.api.docs.

License

MIT, Copyright (c) 2015 Eleme, Inc. Detail see LICENSE-MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.