开源软件名称(OpenSource Name):ledgetech/lua-resty-redis-connector开源软件地址(OpenSource Url):https://github.com/ledgetech/lua-resty-redis-connector开源编程语言(OpenSource Language):Lua 84.4%开源软件介绍(OpenSource Introduction):lua-resty-redis-connectorConnection utilities for lua-resty-redis, making it easy and reliable to connect to Redis hosts, either directly or via Redis Sentinel. SynopsisQuick and simple authenticated connection on localhost to DB 2: local redis, err = require("resty.redis.connector").new({
url = "redis://PASSWORD@127.0.0.1:6379/2",
}):connect() More verbose configuration, with timeouts and a default password: local rc = require("resty.redis.connector").new({
connect_timeout = 50,
send_timeout = 5000,
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,
send_timeout = 5000,
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 formatIf the Note: this is a behaviour change as of v0.06. Previously, the DSN values would take precedence. Direct Redis connectionsThe format for connecting directly to Redis is:
The Use of username requires Redis 6.0.0 or newer. Connections via Redis SentinelWhen connecting via Redis Sentinel, the format is as follows:
Again, On versions of Redis newer than 5.0.1, Sentinels can optionally require their
own password. If enabled, provide this password in the A table of local redis, err = rc:connect{
url = "sentinel://mymaster:a/2",
sentinels = {
{ host = "127.0.0.1", port = 26379 },
},
sentinel_username = "default",
sentinel_password = "password"
} Proxy ModeEnable the Proxy mode will disable switching to a DB on connect. Unsupported commands
(defaults to those not supported by Twemproxy) will return
Disabled commandsIf configured as a table of commands, the command methods will be replaced by a
function which immediately returns Default Parameters{
connect_timeout = 100,
send_timeout = 1000,
read_timeout = 1000,
keepalive_timeout = 60000,
keepalive_poolsize = 30,
-- ssl, ssl_verify, server_name, pool, pool_size, backlog
-- see: https://github.com/openresty/lua-resty-redis#connect
connection_options = {},
host = "127.0.0.1",
port = "6379",
path = "", -- unix socket path, e.g. /tmp/redis.sock
username = "",
password = "",
sentinel_username = "",
sentinel_password = "",
db = 0,
master_name = "mymaster",
role = "master", -- master | slave
sentinels = {},
connection_is_proxied = false,
disabled_commands = {},
} APInew
Creates the Redis Connector object, overriding default params with the ones given.
In case of failures, returns connect
Attempts to create a connection, according to the Note that
set_keepalive
Attempts to place the given Redis connection on the keepalive pool, according to
timeout and poolsize params given in This allows an application to release resources without having to keep track of application wide keepalive settings. Returns UtilitiesThe following methods are not typically needed, but may be useful if a custom interface is required. connect_via_sentinel
Returns a Redis connection by first accessing a sentinel as supplied by the
try_hosts
Tries the hosts supplied in order and returns the first successful connection. connect_to_host
Attempts to connect to the supplied sentinel.get_master
Given a connected Sentinel instance and a master name, will return the current master Redis instance. sentinel.get_slaves
Given a connected Sentinel instance and a master name, will return a list of registered slave Redis instances. AuthorJames Hurst james@pintsized.co.uk LicenceThis module is licensed under the 2-clause BSD license. Copyright (c) James Hurst james@pintsized.co.uk All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
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. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论