|
1 | 1 | local sub = string.sub |
2 | 2 | local tonumber = tonumber |
| 3 | +local fmt = string.format |
3 | 4 |
|
4 | 5 | local redis = require 'resty.redis' |
5 | 6 | local env = require 'resty.env' |
@@ -152,22 +153,22 @@ function _M.connect_redis(options) |
152 | 153 |
|
153 | 154 | local ok, err = red:connect(_M.resolve(host, port)) |
154 | 155 | if not ok then |
155 | | - return nil, _M.error("failed to connect to redis on ", host, ":", port, ": ", err) |
| 156 | + return nil, fmt("failed to connect to redis on %s:%d, err: %s",host, port, err) |
156 | 157 | end |
157 | 158 |
|
158 | 159 | if opts.password then |
159 | | - ok = red:auth(opts.password) |
| 160 | + ok, err = red:auth(opts.password) |
160 | 161 |
|
161 | 162 | if not ok then |
162 | | - return nil, _M.error("failed to auth on redis ", host, ":", port) |
| 163 | + return nil, fmt("failed to auth on redis %s:%d, err: %s", host, port, err) |
163 | 164 | end |
164 | 165 | end |
165 | 166 |
|
166 | 167 | if opts.db then |
167 | | - ok = red:select(opts.db) |
| 168 | + ok, err = red:select(opts.db) |
168 | 169 |
|
169 | 170 | if not ok then |
170 | | - return nil, _M.error("failed to select db ", opts.db, " on redis ", host, ":", port) |
| 171 | + return nil, fmt("failed to select db %s on redis %s:%d, err: %s", opts.db, host, port, err) |
171 | 172 | end |
172 | 173 | end |
173 | 174 |
|
|
0 commit comments