You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* convert tabs to spaces
* add send_timeout parameter
For backwards compatibility, if the user gives a `read_timeout` but no
`send_timeout`, we assume they want a `send_timeout` matching their
`read_timeout`. If neither are given, the defaults apply.
* fallback send_timeout in all cases
We must do this for connector level config, as well as connection level
config. Also moved dsn fallbacks into a utility function.
* format readme for better source readability
* document send_timeout
* add tests for send timeout backwards compatibility
* suppress socket errors
There are spurious socket errors in the logs when using `tcpsock:settimeouts` which only appear in certain environments and are not related to the socket being tested. The socket is not in an error state, and all of our tests pass with proper checks for errors. So we now suppress the built in errors, as recommended in the lua-nginx-module docs.
* bump nginx to 1.19.9
Something is broken in the openresty patch set, but modules using 1.19.9
seem to build in travis fine.
Connection utilities for [lua-resty-redis](https://github.com/openresty/lua-resty-redis), making it easy and reliable to connect to Redis hosts, either directly or via [Redis Sentinel](http://redis.io/topics/sentinel).
6
+
Connection utilities for
7
+
[lua-resty-redis](https://github.com/openresty/lua-resty-redis), making it easy
8
+
and reliable to connect to Redis hosts, either directly or via [Redis
9
+
Sentinel](http://redis.io/topics/sentinel).
6
10
7
11
8
12
## Synopsis
@@ -20,6 +24,7 @@ More verbose configuration, with timeouts and a default password:
20
24
```lua
21
25
localrc=require("resty.redis.connector").new({
22
26
connect_timeout=50,
27
+
send_timeout=5000,
23
28
read_timeout=5000,
24
29
keepalive_timeout=30000,
25
30
password="mypass",
@@ -39,6 +44,7 @@ Keep all config in a table, to easily create / close connections as needed:
39
44
```lua
40
45
localrc=require("resty.redis.connector").new({
41
46
connect_timeout=50,
47
+
send_timeout=5000,
42
48
read_timeout=5000,
43
49
keepalive_timeout=30000,
44
50
@@ -55,7 +61,8 @@ local redis, err = rc:connect()
55
61
localok, err=rc:set_keepalive(redis)
56
62
```
57
63
58
-
[connect](#connect) can be used to override some defaults given in [new](#new), which are pertinent to this connection only.
64
+
[connect](#connect) can be used to override some defaults given in [new](#new),
65
+
which are pertinent to this connection only.
59
66
60
67
61
68
```lua
@@ -73,17 +80,20 @@ local redis, err = rc:connect({
73
80
74
81
## DSN format
75
82
76
-
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.
83
+
If the `params.url` field is present then it will be parsed to set the other
84
+
params. Any manually specified params will override values given in the DSN.
77
85
78
-
*Note: this is a behaviour change as of v0.06. Previously, the DSN values would take precedence.*
86
+
*Note: this is a behaviour change as of v0.06. Previously, the DSN values would
87
+
take precedence.*
79
88
80
89
### Direct Redis connections
81
90
82
91
The format for connecting directly to Redis is:
83
92
84
93
`redis://USERNAME:PASSWORD@HOST:PORT/DB`
85
94
86
-
The `USERNAME`, `PASSWORD` and `DB` fields are optional, all other components are required.
95
+
The `USERNAME`, `PASSWORD` and `DB` fields are optional, all other components
96
+
are required.
87
97
88
98
Use of username requires Redis 6.0.0 or newer.
89
99
@@ -93,10 +103,13 @@ When connecting via Redis Sentinel, the format is as follows:
Again, `USERNAME`, `PASSWORD` and `DB` are optional. `ROLE` must be either `m` or `s` for master / slave respectively.
106
+
Again, `USERNAME`, `PASSWORD` and `DB` are optional. `ROLE` must be either `m`
107
+
or `s` for master / slave respectively.
97
108
98
-
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.
99
-
On Redis 6.2.0 and newer you can pass username using `sentinel_username` parameter.
109
+
On versions of Redis newer than 5.0.1, Sentinels can optionally require their
110
+
own password. If enabled, provide this password in the `sentinel_password`
111
+
parameter. On Redis 6.2.0 and newer you can pass username using
112
+
`sentinel_username` parameter.
100
113
101
114
A table of `sentinels` must also be supplied. e.g.
102
115
@@ -113,31 +126,40 @@ local redis, err = rc:connect{
113
126
114
127
## Proxy Mode
115
128
116
-
Enable the `connection_is_proxied` parameter if connecting to Redis through a proxy service (e.g. Twemproxy).
117
-
These proxies generally only support a limited sub-set of Redis commands, those which do not require state and do not affect multiple keys.
118
-
Databases and transactions are also not supported.
129
+
Enable the `connection_is_proxied` parameter if connecting to Redis through a
130
+
proxy service (e.g. Twemproxy). These proxies generally only support a limited
131
+
sub-set of Redis commands, those which do not require state and do not affect
132
+
multiple keys. Databases and transactions are also not supported.
119
133
120
-
Proxy mode will disable switching to a DB on connect.
121
-
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.
134
+
Proxy mode will disable switching to a DB on connect. Unsupported commands
135
+
(defaults to those not supported by Twemproxy) will return `nil, err`
136
+
immediately rather than being sent to the proxy, which can result in dropped
137
+
connections.
122
138
123
139
`discard` will not be sent when adding connections to the keepalive pool
124
140
125
141
126
142
## Disabled commands
127
143
128
-
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
144
+
If configured as a table of commands, the command methods will be replaced by a
145
+
function which immediately returns `nil, err` without forwarding the command to
146
+
the server
129
147
130
148
## Default Parameters
131
149
132
150
133
151
```lua
134
152
{
135
153
connect_timeout=100,
154
+
send_timeout=1000,
136
155
read_timeout=1000,
137
-
connection_options= {}, -- pool, etc
138
156
keepalive_timeout=60000,
139
157
keepalive_poolsize=30,
140
158
159
+
-- ssl, ssl_verify, server_name, pool, pool_size, backlog
path="", -- unix socket path, e.g. /tmp/redis.sock
@@ -175,16 +197,21 @@ If configured as a table of commands, the command methods will be replaced by a
175
197
176
198
`syntax: rc = redis_connector.new(params)`
177
199
178
-
Creates the Redis Connector object, overring default params with the ones given. In case of failures, returns `nil` and a string describing the error.
200
+
Creates the Redis Connector object, overring default params with the ones given.
201
+
In case of failures, returns `nil` and a string describing the error.
179
202
180
203
181
204
### connect
182
205
183
206
`syntax: redis, err = rc:connect(params)`
184
207
185
-
Attempts to create a connection, according to the [params](#parameters) 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.
208
+
Attempts to create a connection, according to the [params](#parameters)
209
+
supplied, falling back to defaults given in `new` or the predefined defaults. If
210
+
a connection cannot be made, returns `nil` and a string describing the reason.
186
211
187
-
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`.
212
+
Note that `params` given here do not change the connector's own configuration,
213
+
and are only used to alter this particular connection operation. As such, the
214
+
following parameters have no meaning when given in `connect`.
188
215
189
216
*`keepalive_poolsize`
190
217
*`keepalive_timeout`
@@ -196,24 +223,28 @@ Note that `params` given here do not change the connector's own configuration, a
196
223
197
224
`syntax: ok, err = rc:set_keepalive(redis)`
198
225
199
-
Attempts to place the given Redis connection on the keepalive pool, according to timeout and poolsize params given in `new` or the predefined defaults.
226
+
Attempts to place the given Redis connection on the keepalive pool, according to
227
+
timeout and poolsize params given in `new` or the predefined defaults.
200
228
201
-
This allows an application to release resources without having to keep track of application wide keepalive settings.
229
+
This allows an application to release resources without having to keep track of
230
+
application wide keepalive settings.
202
231
203
232
Returns `1` or in the case of error, `nil` and a string describing the error.
204
233
205
234
206
235
## Utilities
207
236
208
-
The following methods are not typically needed, but may be useful if a custom interface is required.
237
+
The following methods are not typically needed, but may be useful if a custom
Given a connected Sentinel instance and a master name, will return a list of registered slave Redis instances.
276
+
Given a connected Sentinel instance and a master name, will return a list of
277
+
registered slave Redis instances.
245
278
246
279
247
280
# Author
@@ -257,10 +290,23 @@ Copyright (c) James Hurst <james@pintsized.co.uk>
257
290
258
291
All rights reserved.
259
292
260
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
261
-
262
-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
263
-
264
-
* 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.
265
-
266
-
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.
293
+
Redistribution and use in source and binary forms, with or without modification,
294
+
are permitted provided that the following conditions are met:
295
+
296
+
* Redistributions of source code must retain the above copyright notice, this
297
+
list of conditions and the following disclaimer.
298
+
299
+
* Redistributions in binary form must reproduce the above copyright notice, this
300
+
list of conditions and the following disclaimer in the documentation and/or
301
+
other materials provided with the distribution.
302
+
303
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
304
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
305
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
306
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
307
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
308
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
309
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
310
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
311
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
312
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0 commit comments