All Projects → ledgetech → Lua Resty Redis Connector

ledgetech / Lua Resty Redis Connector

Connection utilities for lua-resty-redis

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to Lua Resty Redis Connector

Ledge
An RFC compliant and ESI capable HTTP cache for Nginx / OpenResty, backed by Redis
Stars: ✭ 412 (+121.51%)
Mutual labels:  openresty, redis, redis-sentinel, luajit
Luajit.io
luajit io framework
Stars: ✭ 277 (+48.92%)
Mutual labels:  openresty, luajit, nginx
Oneinstack
OneinStack - A PHP/JAVA Deployment Tool
Stars: ✭ 1,983 (+966.13%)
Mutual labels:  openresty, redis, nginx
Lua Nginx Redis
🌺 Redis、Lua、Nginx、OpenResty 笔记和资料
Stars: ✭ 757 (+306.99%)
Mutual labels:  openresty, redis, luajit
Lnmp
LEMP stack/LAMP stack/LNMP stack installation scripts for CentOS/Redhat Debian and Ubuntu
Stars: ✭ 2,488 (+1237.63%)
Mutual labels:  openresty, redis, nginx
Lua Resty Http
Lua HTTP client cosocket driver for OpenResty / ngx_lua.
Stars: ✭ 1,647 (+785.48%)
Mutual labels:  openresty, luajit, nginx
Apioak
Full Lifecycle Management API Gateway.
Stars: ✭ 335 (+80.11%)
Mutual labels:  openresty, luajit, nginx
Lua Resty Post
HTTP post utility for openresty
Stars: ✭ 30 (-83.87%)
Mutual labels:  openresty, luajit, nginx
Lua Resty Redis Util
openresty/lua-resty-redis 封装工具类
Stars: ✭ 90 (-51.61%)
Mutual labels:  openresty, redis, nginx
Lua Resty Route
URL Routing Library for OpenResty Supporting Pluggable Matching Engines
Stars: ✭ 88 (-52.69%)
Mutual labels:  openresty, luajit, nginx
Api Umbrella
Open source API management platform
Stars: ✭ 1,735 (+832.8%)
Mutual labels:  openresty, luajit, nginx
Motan Openresty
A cross-language RPC framework for rapid development of high performance distributed services based on OpenResty.
Stars: ✭ 117 (-37.1%)
Mutual labels:  openresty, luajit, nginx
Lua Resty Repl
Interactive console (REPL) for Openresty and luajit code
Stars: ✭ 165 (-11.29%)
Mutual labels:  openresty, luajit, nginx
Ngx Oauth
OAuth 2.0 proxy for nginx written in Lua.
Stars: ✭ 146 (-21.51%)
Mutual labels:  openresty, nginx
Lovinghome Real Estate Platform
⚡️基于springboot+MyBatis+FreeMarker+redis+nginx+Echarts+druid等技术的JavaWeb项目------恋家房产平台(采用B/S架构,项目包含前后台,分为前台展示系统及后台管理系统。前台系统包含首页门户、登录注册、房产推荐、房产详情、热门房产、房产及小区搜索、经纪人列表及经纪机构创建、创建房产、房产百科、地图找房、用户个人中心、房产评论、房产打分等模块。 后台管理系统包含房产信息管理、用户管理、管理员管理、小区信息管理、博客管理、评论管理、经纪人管理、系统统计与多种图表展示、数据报表导入导出等模块。系统介绍及详细功能点、技术点见项目内文档描述)
Stars: ✭ 140 (-24.73%)
Mutual labels:  redis, nginx
Camellia
camellia framework by netease-im. provider: 1) redis-client; 2) redis-proxy(redis-sentinel/redis-cluster); 3) hbase-client; 4) others
Stars: ✭ 146 (-21.51%)
Mutual labels:  redis, redis-sentinel
Lua Resty Auto Ssl
On the fly (and free) SSL registration and renewal inside OpenResty/nginx with Let's Encrypt.
Stars: ✭ 1,786 (+860.22%)
Mutual labels:  openresty, nginx
Meetingfilm
基于微服务架构的在线电影购票平台
Stars: ✭ 149 (-19.89%)
Mutual labels:  redis, nginx
Upyun Resty
UPYUN's open source software for OpenResty development
Stars: ✭ 150 (-19.35%)
Mutual labels:  openresty, nginx
Study
全栈工程师学习笔记;Spring登录、shiro登录、CAS单点登录和Spring boot oauth2单点登录;Spring data cache 缓存,支持Redis和EHcahce; web安全,常见web安全漏洞以及解决思路;常规组件,比如redis、mq等;quartz定时任务,支持持久化数据库,动态维护启动暂停关闭;docker基本用法,常用image镜像使用,Docker-MySQL、docker-Postgres、Docker-nginx、Docker-nexus、Docker-Redis、Docker-RabbitMQ、Docker-zookeeper、Docker-es、Docker-zipkin、Docker-ELK等;mybatis实践、spring实践、spring boot实践等常用集成;基于redis的分布式锁;基于shared-jdbc的分库分表,支持原生jdbc和Spring Boot Mybatis
Stars: ✭ 159 (-14.52%)
Mutual labels:  redis, nginx

lua-resty-redis-connector

Build Status

Connection utilities for lua-resty-redis, making it easy and reliable to connect to Redis hosts, either directly or via Redis Sentinel.

Synopsis

Quick and simple authenticated connection on localhost to DB 2:

local redis, err = require("resty.redis.connector").new({
    url = "redis://[email protected]:6379/2",
}):connect()

More verbose configuration, with timeouts and a default password:

local rc = require("resty.redis.connector").new({
    connect_timeout = 50,
    read_timeout = 5000,
    keepalive_timeout = 30000,
    password = "mypass",
})

local redis, err = rc:connect({
    url = "redis://127.0.0.1:6379/2",
})

-- ...

local ok, err = rc:set_keepalive(redis)  -- uses keepalive params

Keep all config in a table, to easily create / close connections as needed:

local rc = require("resty.redis.connector").new({
    connect_timeout = 50,
    read_timeout = 5000,
    keepalive_timeout = 30000,

    host = "127.0.0.1",
    port = 6379,
    db = 2,
    password = "mypass",
})

local redis, err = rc:connect()

-- ...

local ok, err = rc:set_keepalive(redis)

connect can be used to override some defaults given in new, which are pertinent to this connection only.

local rc = require("resty.redis.connector").new({
    host = "127.0.0.1",
    port = 6379,
    db = 2,
})

local redis, err = rc:connect({
    db = 5,
})

DSN format

If the params.url field is present then it will be parsed to set the other params. Any manually specified params will override values given in the DSN.

Note: this is a behaviour change as of v0.06. Previously, the DSN values would take precedence.

Direct Redis connections

The format for connecting directly to Redis is:

redis://[email protected]:PORT/DB

The PASSWORD and DB fields are optional, all other components are required.

Connections via Redis Sentinel

When connecting via Redis Sentinel, the format is as follows:

sentinel://[email protected]_NAME:ROLE/DB

Again, PASSWORD and DB are optional. ROLE must be either m or s for master / slave respectively.

On versions of Redis newer than 5.0.1, Sentinels can optionally require their own password. If enabled, provide this password in the sentinel_password parameter.

A table of sentinels must also be supplied. e.g.

local redis, err = rc:connect{
    url = "sentinel://mymaster:a/2",
    sentinels = {
        { host = "127.0.0.1", port = 26379 },
    },
    sentinel_password = "password"
}

Proxy Mode

Enable the connection_is_proxied parameter if connecting to Redis through a proxy service (e.g. Twemproxy). These proxies generally only support a limited sub-set of Redis commands, those which do not require state and do not affect multiple keys. Databases and transactions are also not supported.

Proxy mode will disable switching to a DB on connect. Unsupported commands (defaults to those not supported by Twemproxy) will return nil, err immediately rather than being sent to the proxy, which can result in dropped connections.

discard will not be sent when adding connections to the keepalive pool

Disabled commands

If configured as a table of commands, the command methods will be replaced by a function which immediately returns nil, err without forwarding the command to the server

Default Parameters

{
    connect_timeout = 100,
    read_timeout = 1000,
    connection_options = {}, -- pool, etc
    keepalive_timeout = 60000,
    keepalive_poolsize = 30,

    host = "127.0.0.1",
    port = "6379",
    path = "",  -- unix socket path, e.g. /tmp/redis.sock
    password = "",
    sentinel_password = "",
    db = 0,

    master_name = "mymaster",
    role = "master",  -- master | slave
    sentinels = {},

    connection_is_proxied = false,

    disabled_commands = {},
}

API

new

syntax: rc = redis_connector.new(params)

Creates the Redis Connector object, overring default params with the ones given. In case of failures, returns nil and a string describing the error.

connect

syntax: redis, err = rc:connect(params)

Attempts to create a connection, according to the params supplied, falling back to defaults given in new or the predefined defaults. If a connection cannot be made, returns nil and a string describing the reason.

Note that params given here do not change the connector's own configuration, and are only used to alter this particular connection operation. As such, the following parameters have no meaning when given in connect.

  • keepalive_poolsize
  • keepalive_timeout
  • connection_is_proxied
  • disabled_commands

set_keepalive

syntax: ok, err = rc:set_keepalive(redis)

Attempts to place the given Redis connection on the keepalive pool, according to timeout and poolsize params given in new or the predefined defaults.

This allows an application to release resources without having to keep track of application wide keepalive settings.

Returns 1 or in the case of error, nil and a string describing the error.

Utilities

The following methods are not typically needed, but may be useful if a custom interface is required.

connect_via_sentinel

syntax: redis, err = rc:connect_via_sentinel(params)

Returns a Redis connection by first accessing a sentinel as supplied by the params.sentinels table, and querying this with the params.master_name and params.role.

try_hosts

syntax: redis, err = rc:try_hosts(hosts)

Tries the hosts supplied in order and returns the first successful connection.

connect_to_host

syntax: redis, err = rc:connect_to_host(host)

Attempts to connect to the supplied host.

sentinel.get_master

syntax: master, err = sentinel.get_master(sentinel, master_name)

Given a connected Sentinel instance and a master name, will return the current master Redis instance.

sentinel.get_slaves

syntax: slaves, err = sentinel.get_slaves(sentinel, master_name)

Given a connected Sentinel instance and a master name, will return a list of registered slave Redis instances.

Author

James Hurst [email protected]

Licence

This module is licensed under the 2-clause BSD license.

Copyright (c) James Hurst [email protected]

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].