mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Remove unused test files and certificates from lua-resty-redis
This commit is contained in:
parent
d3a25aca34
commit
714105474b
15 changed files with 0 additions and 3431 deletions
57
src/deps/src/lua-resty-redis/t/Test.pm
vendored
57
src/deps/src/lua-resty-redis/t/Test.pm
vendored
|
|
@ -1,57 +0,0 @@
|
|||
package t::Test;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::Nginx::Socket::Lua::Stream -Base;
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
my $HtmlDir = html_dir;
|
||||
|
||||
our @EXPORT = qw($GlobalConfig);
|
||||
our $GlobalConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;;";
|
||||
lua_package_cpath "/usr/local/openresty-debug/lualib/?.so;/usr/local/openresty/lualib/?.so;;";
|
||||
};
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
|
||||
|
||||
no_long_string();
|
||||
|
||||
add_block_preprocessor(sub {
|
||||
my $block = shift;
|
||||
|
||||
if (!defined $block->http_only) {
|
||||
if (defined($ENV{TEST_SUBSYSTEM}) && $ENV{TEST_SUBSYSTEM} eq "stream") {
|
||||
if (!defined $block->stream_config) {
|
||||
$block->set_value("stream_config", $block->global_config);
|
||||
}
|
||||
if (!defined $block->stream_server_config) {
|
||||
$block->set_value("stream_server_config", $block->server_config);
|
||||
}
|
||||
if (defined $block->internal_server_error) {
|
||||
$block->set_value("stream_respons", "");
|
||||
}
|
||||
} else {
|
||||
if (!defined $block->http_config) {
|
||||
$block->set_value("http_config", $block->global_config);
|
||||
}
|
||||
if (!defined $block->request) {
|
||||
$block->set_value("request", <<\_END_);
|
||||
GET /t
|
||||
_END_
|
||||
}
|
||||
if (!defined $block->config) {
|
||||
$block->set_value("config", "location /t {\n" . $block->server_config . "\n}");
|
||||
}
|
||||
if (defined $block->internal_server_error) {
|
||||
$block->set_value("error_code", 500);
|
||||
$block->set_value("ignore_response_body", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
1;
|
||||
245
src/deps/src/lua-resty-redis/t/bugs.t
vendored
245
src/deps/src/lua-resty-redis/t/bugs.t
vendored
|
|
@ -1,245 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use t::Test;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
log_level 'warn';
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: github issue #108: ngx.location.capture + redis.set_keepalive
|
||||
--- http_only
|
||||
--- http_config eval: $::GlobalConfig
|
||||
--- config
|
||||
location /r1 {
|
||||
default_type text/html;
|
||||
set $port $TEST_NGINX_REDIS_PORT;
|
||||
#lua_code_cache off;
|
||||
lua_need_request_body on;
|
||||
content_by_lua_file html/r1.lua;
|
||||
}
|
||||
|
||||
location /r2 {
|
||||
default_type text/html;
|
||||
set $port $TEST_NGINX_REDIS_PORT;
|
||||
#lua_code_cache off;
|
||||
lua_need_request_body on;
|
||||
content_by_lua_file html/r2.lua;
|
||||
}
|
||||
|
||||
location /anyurl {
|
||||
internal;
|
||||
proxy_pass http://127.0.0.1:$server_port/dummy;
|
||||
}
|
||||
|
||||
location = /dummy {
|
||||
echo dummy;
|
||||
}
|
||||
--- user_files
|
||||
>>> r1.lua
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
local ok, err = red:connect("127.0.0.1", ngx.var.port)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
local ok, err = red:flushall()
|
||||
if not ok then
|
||||
ngx.say("failed to flushall: ", err)
|
||||
return
|
||||
end
|
||||
ok, err = red:set_keepalive()
|
||||
if not ok then
|
||||
ngx.say("failed to set keepalive: ", err)
|
||||
return
|
||||
end
|
||||
local http_ress = ngx.location.capture("/r2") -- 1
|
||||
ngx.say("ok")
|
||||
|
||||
>>> r2.lua
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
local ok, err = red:connect("127.0.0.1", ngx.var.port) --2
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
local res = ngx.location.capture("/anyurl") --3
|
||||
--- request
|
||||
GET /r1
|
||||
--- response_body
|
||||
ok
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: exit(404) after I/O (ngx_lua github issue #110
|
||||
https://github.com/chaoslawful/lua-nginx-module/issues/110
|
||||
--- http_only
|
||||
--- http_config eval: $::GlobalConfig
|
||||
--- config
|
||||
error_page 400 /400.html;
|
||||
error_page 404 /404.html;
|
||||
location /foo {
|
||||
access_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(2000) -- 2 sec
|
||||
|
||||
-- ngx.log(ngx.ERR, "hello");
|
||||
|
||||
-- or connect to a unix domain socket file listened
|
||||
-- by a redis server:
|
||||
-- local ok, err = red:connect("unix:/path/to/redis.sock")
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:set("dog", "an animal")
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, "failed to set dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
-- ngx.say("set dog: ", res)
|
||||
|
||||
local res, err = red:get("dog")
|
||||
if err then
|
||||
ngx.log(ngx.ERR, "failed to get dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, "dog not found.")
|
||||
return
|
||||
end
|
||||
|
||||
-- ngx.say("dog: ", res)
|
||||
|
||||
-- red:close()
|
||||
local ok, err = red:set_keepalive(0, 100)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to set keepalive: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.exit(404)
|
||||
';
|
||||
echo Hello;
|
||||
}
|
||||
--- user_files
|
||||
>>> 400.html
|
||||
Bad request, dear...
|
||||
>>> 404.html
|
||||
Not found, dear...
|
||||
--- request
|
||||
GET /foo
|
||||
--- response_body
|
||||
Not found, dear...
|
||||
--- error_code: 404
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: set and get an empty string
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
-- or connect to a unix domain socket file listened
|
||||
-- by a redis server:
|
||||
-- local ok, err = red:connect("unix:/path/to/redis.sock")
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:set("dog", "")
|
||||
if not res then
|
||||
ngx.say("failed to set dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("set dog: ", res)
|
||||
|
||||
for i = 1, 2 do
|
||||
local res, err = red:get("dog")
|
||||
if err then
|
||||
ngx.say("failed to get dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
if not res then
|
||||
ngx.say("dog not found.")
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("dog: ", res)
|
||||
end
|
||||
|
||||
red:close()
|
||||
';
|
||||
--- response_body
|
||||
set dog: OK
|
||||
dog:
|
||||
dog:
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 4: ngx.exec() after red:get()
|
||||
--- http_only
|
||||
--- http_config eval: $::GlobalConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:get("dog")
|
||||
if err then
|
||||
ngx.say("failed to get dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.exec("/hello")
|
||||
';
|
||||
}
|
||||
|
||||
location = /hello {
|
||||
echo hello world;
|
||||
}
|
||||
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
hello world
|
||||
--- no_error_log
|
||||
[error]
|
||||
17
src/deps/src/lua-resty-redis/t/cert/test.crt
vendored
17
src/deps/src/lua-resty-redis/t/cert/test.crt
vendored
|
|
@ -1,17 +0,0 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICqTCCAhICCQClDm1WkreW4jANBgkqhkiG9w0BAQUFADCBlzELMAkGA1UEBhMC
|
||||
VVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28x
|
||||
EjAQBgNVBAoMCU9wZW5SZXN0eTESMBAGA1UECwwJT3BlblJlc3R5MREwDwYDVQQD
|
||||
DAh0ZXN0LmNvbTEgMB4GCSqGSIb3DQEJARYRYWdlbnR6aEBnbWFpbC5jb20wIBcN
|
||||
MTQwNzIxMDMyMzQ3WhgPMjE1MTA2MTMwMzIzNDdaMIGXMQswCQYDVQQGEwJVUzET
|
||||
MBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzESMBAG
|
||||
A1UECgwJT3BlblJlc3R5MRIwEAYDVQQLDAlPcGVuUmVzdHkxETAPBgNVBAMMCHRl
|
||||
c3QuY29tMSAwHgYJKoZIhvcNAQkBFhFhZ2VudHpoQGdtYWlsLmNvbTCBnzANBgkq
|
||||
hkiG9w0BAQEFAAOBjQAwgYkCgYEA6P18zUvtmaKQK2xePy8ZbFwSyTLw+jW6t9eZ
|
||||
aiTec8X3ibN9WemrxHzkTRikxP3cAQoITRuZiQvF4Q7DO6wMkz/b0zwfgX5uedGq
|
||||
047AJP6n/mwlDOjGSNomBLoXQzo7tVe60ikEm3ZyDUqnJPJMt3hImO5XSop4MPMu
|
||||
Za9WhFcCAwEAATANBgkqhkiG9w0BAQUFAAOBgQA4OBb9bOyWB1//93nSXX1mdENZ
|
||||
IQeyTK0Dd6My76lnZxnZ4hTWrvvd0b17KLDU6JnS2N5ee3ATVkojPidRLWLIhnh5
|
||||
0eXrcKalbO2Ce6nShoFvQCQKXN2Txmq2vO/Mud2bHAWwJALg+qi1Iih/gVYB9sct
|
||||
FLg8zFOzRlYiU+6Mmw==
|
||||
-----END CERTIFICATE-----
|
||||
15
src/deps/src/lua-resty-redis/t/cert/test.key
vendored
15
src/deps/src/lua-resty-redis/t/cert/test.key
vendored
|
|
@ -1,15 +0,0 @@
|
|||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXgIBAAKBgQDo/XzNS+2ZopArbF4/LxlsXBLJMvD6Nbq315lqJN5zxfeJs31Z
|
||||
6avEfORNGKTE/dwBCghNG5mJC8XhDsM7rAyTP9vTPB+Bfm550arTjsAk/qf+bCUM
|
||||
6MZI2iYEuhdDOju1V7rSKQSbdnINSqck8ky3eEiY7ldKingw8y5lr1aEVwIDAQAB
|
||||
AoGBANgB66sKMga2SKN5nQdHS3LDCkevCutu1OWM5ZcbB4Kej5kC57xsf+tzPtab
|
||||
emeIVGhCPOAALqB4YcT+QtMX967oM1MjcFbtH7si5oq6UYyp3i0G9Si6jIoVHz3+
|
||||
8yOUaqwKbK+bRX8VS0YsHZmBsPK5ryN50iUwsU08nemoA94BAkEA9GS9Q5OPeFkM
|
||||
tFxsIQ1f2FSsZAuN/1cpZgJqY+YaAN7MSPGTWyfd7nWG/Zgk3GO9/2ihh4gww+7B
|
||||
To09GkmW4QJBAPQOHC2V+t2TA98+6Lj6+TYwcGEkhOENfVpH25mQ+kXgF/1Bd6rA
|
||||
nosT1bdAY+SnmWXbSw6Kv5C20Em+bEX8WjcCQCSRRjhsRdVODbaW9Z7kb2jhEoJN
|
||||
sEt6cTlQNzcHYPCsZYisjM3g4zYg47fiIfHQAsfKkhDDcfh/KvFj9LaQOEECQQCH
|
||||
eBWYEDpSJ7rsfqT7mQQgWj7nDThdG/nK1TxGP71McBmg0Gg2dfkLRhVJRQqt74Is
|
||||
kc9V4Rp4n6F6baL4Lh19AkEA6pZZer0kg3Kv9hjhaITIKUYdfIp9vYnDRWbQlBmR
|
||||
atV8V9u9q2ETZvqfHpN+9Lu6NYR4yXIEIRf1bnIZ/mr9eQ==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
27
src/deps/src/lua-resty-redis/t/count.t
vendored
27
src/deps/src/lua-resty-redis/t/count.t
vendored
|
|
@ -1,27 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use t::Test;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: module size of resty.redis
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
n = 0
|
||||
for _, _ in pairs(redis) do
|
||||
n = n + 1
|
||||
end
|
||||
ngx.say("size: ", n)
|
||||
';
|
||||
--- response_body
|
||||
size: 56
|
||||
--- no_error_log
|
||||
[error]
|
||||
128
src/deps/src/lua-resty-redis/t/hmset.t
vendored
128
src/deps/src/lua-resty-redis/t/hmset.t
vendored
|
|
@ -1,128 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use t::Test;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks()) - 2;
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: hmset key-pairs
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:hmset("animals", "dog", "bark", "cat", "meow")
|
||||
if not res then
|
||||
ngx.say("failed to set animals: ", err)
|
||||
return
|
||||
end
|
||||
ngx.say("hmset animals: ", res)
|
||||
|
||||
local res, err = red:hmget("animals", "dog", "cat")
|
||||
if not res then
|
||||
ngx.say("failed to get animals: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("hmget animals: ", res)
|
||||
|
||||
red:close()
|
||||
';
|
||||
--- response_body
|
||||
hmset animals: OK
|
||||
hmget animals: barkmeow
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: hmset lua tables
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local t = { dog = "bark", cat = "meow", cow = "moo" }
|
||||
local res, err = red:hmset("animals", t)
|
||||
if not res then
|
||||
ngx.say("failed to set animals: ", err)
|
||||
return
|
||||
end
|
||||
ngx.say("hmset animals: ", res)
|
||||
|
||||
local res, err = red:hmget("animals", "dog", "cat", "cow")
|
||||
if not res then
|
||||
ngx.say("failed to get animals: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("hmget animals: ", res)
|
||||
|
||||
red:close()
|
||||
';
|
||||
--- response_body
|
||||
hmset animals: OK
|
||||
hmget animals: barkmeowmoo
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: hmset a single scalar
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:hmset("animals", "cat")
|
||||
if not res then
|
||||
ngx.say("failed to set animals: ", err)
|
||||
return
|
||||
end
|
||||
ngx.say("hmset animals: ", res)
|
||||
|
||||
local res, err = red:hmget("animals", "cat")
|
||||
if not res then
|
||||
ngx.say("failed to get animals: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("hmget animals: ", res)
|
||||
|
||||
red:close()
|
||||
';
|
||||
--- internal_server_error
|
||||
--- error_log
|
||||
table expected, got string
|
||||
55
src/deps/src/lua-resty-redis/t/mock.t
vendored
55
src/deps/src/lua-resty-redis/t/mock.t
vendored
|
|
@ -1,55 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use t::Test;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (4 * blocks());
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: continue using the obj when read timeout happens
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", 1921);
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
red:set_timeout(100) -- 0.1 sec
|
||||
|
||||
for i = 1, 2 do
|
||||
local data, err = red:get("foo")
|
||||
if not data then
|
||||
ngx.say("failed to get: ", err)
|
||||
else
|
||||
ngx.say("get: ", data);
|
||||
end
|
||||
ngx.sleep(0.1)
|
||||
end
|
||||
|
||||
red:close()
|
||||
';
|
||||
--- tcp_listen: 1921
|
||||
--- tcp_query eval
|
||||
"*2\r
|
||||
\$3\r
|
||||
get\r
|
||||
\$3\r
|
||||
foo\r
|
||||
"
|
||||
--- tcp_reply eval
|
||||
"\$5\r\nhello\r\n"
|
||||
--- tcp_reply_delay: 150ms
|
||||
--- response_body
|
||||
failed to get: timeout
|
||||
failed to get: closed
|
||||
--- error_log
|
||||
lua tcp socket read timed out
|
||||
81
src/deps/src/lua-resty-redis/t/module.t
vendored
81
src/deps/src/lua-resty-redis/t/module.t
vendored
|
|
@ -1,81 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use t::Test;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: sanity
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua_block {
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
redis.register_module_prefix("bf")
|
||||
redis.register_module_prefix("test")
|
||||
|
||||
local red = redis:new()
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:del("module_1")
|
||||
if not res then
|
||||
ngx.say(err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:bf():add("module_1", 1)
|
||||
if not res then
|
||||
ngx.say(err)
|
||||
return
|
||||
end
|
||||
ngx.say("receive: ", cjson.encode(res))
|
||||
|
||||
res, err = red:bf():exists("module_1", 1)
|
||||
if not res then
|
||||
ngx.say(err)
|
||||
return
|
||||
end
|
||||
ngx.say("receive: ", cjson.encode(res))
|
||||
|
||||
-- call normal command
|
||||
res, err = red:del("module_1")
|
||||
if not res then
|
||||
ngx.say(err)
|
||||
return
|
||||
end
|
||||
ngx.say("receive: ", cjson.encode(res))
|
||||
|
||||
-- call cached 'exists' again
|
||||
res, err = red:exists("module_1")
|
||||
if not res then
|
||||
ngx.say(err)
|
||||
return
|
||||
end
|
||||
ngx.say("receive: ", cjson.encode(res))
|
||||
|
||||
-- call pre-created 'get' method
|
||||
res, err = red:test():get()
|
||||
if not res then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
red:close()
|
||||
}
|
||||
--- response_body_like
|
||||
receive: 1
|
||||
receive: 1
|
||||
receive: 1
|
||||
receive: 0
|
||||
ERR unknown command `test.get`.+
|
||||
--- no_error_log
|
||||
[error]
|
||||
294
src/deps/src/lua-resty-redis/t/pipeline.t
vendored
294
src/deps/src/lua-resty-redis/t/pipeline.t
vendored
|
|
@ -1,294 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use t::Test;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: basic
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
for i = 1, 2 do
|
||||
red:init_pipeline()
|
||||
|
||||
red:set("dog", "an animal")
|
||||
red:get("dog")
|
||||
red:set("dog", "hello")
|
||||
red:get("dog")
|
||||
|
||||
local results = red:commit_pipeline()
|
||||
local cjson = require "cjson"
|
||||
ngx.say(cjson.encode(results))
|
||||
end
|
||||
|
||||
red:close()
|
||||
';
|
||||
--- response_body
|
||||
["OK","an animal","OK","hello"]
|
||||
["OK","an animal","OK","hello"]
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: cancel automatically
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
red:init_pipeline()
|
||||
|
||||
red:set("dog", "an animal")
|
||||
red:get("dog")
|
||||
|
||||
for i = 1, 2 do
|
||||
red:init_pipeline()
|
||||
|
||||
red:set("dog", "an animal")
|
||||
red:get("dog")
|
||||
red:set("dog", "hello")
|
||||
red:get("dog")
|
||||
|
||||
local results = red:commit_pipeline()
|
||||
local cjson = require "cjson"
|
||||
ngx.say(cjson.encode(results))
|
||||
end
|
||||
|
||||
red:close()
|
||||
';
|
||||
--- response_body
|
||||
["OK","an animal","OK","hello"]
|
||||
["OK","an animal","OK","hello"]
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: cancel explicitly
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
red:init_pipeline()
|
||||
|
||||
red:set("dog", "an animal")
|
||||
red:get("dog")
|
||||
|
||||
red:cancel_pipeline()
|
||||
|
||||
local res, err = red:flushall()
|
||||
if not res then
|
||||
ngx.say("failed to flush all: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("flushall: ", res)
|
||||
|
||||
for i = 1, 2 do
|
||||
red:init_pipeline()
|
||||
|
||||
red:set("dog", "an animal")
|
||||
red:get("dog")
|
||||
red:set("dog", "hello")
|
||||
red:get("dog")
|
||||
|
||||
local results = red:commit_pipeline()
|
||||
local cjson = require "cjson"
|
||||
ngx.say(cjson.encode(results))
|
||||
end
|
||||
|
||||
red:close()
|
||||
';
|
||||
--- response_body
|
||||
flushall: OK
|
||||
["OK","an animal","OK","hello"]
|
||||
["OK","an animal","OK","hello"]
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 4: mixed
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", 6379)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:set("dog", "an aniaml")
|
||||
if not ok then
|
||||
ngx.say("failed to set dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("set result: ", res)
|
||||
|
||||
local res, err = red:get("dog")
|
||||
if not res then
|
||||
ngx.say("failed to get dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
if res == ngx.null then
|
||||
ngx.say("dog not found.")
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("dog: ", res)
|
||||
|
||||
red:init_pipeline()
|
||||
red:set("cat", "Marry")
|
||||
red:set("horse", "Bob")
|
||||
red:get("cat")
|
||||
red:get("horse")
|
||||
local results, err = red:commit_pipeline()
|
||||
if not results then
|
||||
ngx.say("failed to commit the pipelined requests: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
for i, res in ipairs(results) do
|
||||
if type(res) == "table" then
|
||||
if res[1] == false then
|
||||
ngx.say("failed to run command ", i, ": ", res[2])
|
||||
else
|
||||
ngx.say("cmd ", i, ": ", res)
|
||||
end
|
||||
else
|
||||
-- process the scalar value
|
||||
ngx.say("cmd ", i, ": ", res)
|
||||
end
|
||||
end
|
||||
|
||||
-- put it into the connection pool of size 100,
|
||||
-- with 0 idle timeout
|
||||
local ok, err = red:set_keepalive(0, 100)
|
||||
if not ok then
|
||||
ngx.say("failed to set keepalive: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
-- or just close the connection right away:
|
||||
-- local ok, err = red:close()
|
||||
-- if not ok then
|
||||
-- ngx.say("failed to close: ", err)
|
||||
-- return
|
||||
-- end
|
||||
';
|
||||
--- response_body
|
||||
set result: OK
|
||||
dog: an aniaml
|
||||
cmd 1: OK
|
||||
cmd 2: OK
|
||||
cmd 3: Marry
|
||||
cmd 4: Bob
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 5: redis return error in pipeline
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", 6379)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:del("dog")
|
||||
if not res then
|
||||
ngx.say("failed to del dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
red:init_pipeline()
|
||||
red:hkeys("dog")
|
||||
red:set("dog", "an animal")
|
||||
red:hkeys("dog")
|
||||
red:get("dog")
|
||||
local results, err = red:commit_pipeline()
|
||||
if not results then
|
||||
ngx.say("failed to commit the pipelined requests: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
for i, res in ipairs(results) do
|
||||
if type(res) == "table" then
|
||||
if res[1] == false then
|
||||
ngx.say("failed to run command ", i, ": ", res[2])
|
||||
else
|
||||
ngx.say("cmd ", i, ": ", res)
|
||||
end
|
||||
else
|
||||
-- process the scalar value
|
||||
ngx.say("cmd ", i, ": ", res)
|
||||
end
|
||||
end
|
||||
|
||||
-- put it into the connection pool of size 100,
|
||||
-- with 0 idle timeout
|
||||
local ok, err = red:set_keepalive(0, 100)
|
||||
if not ok then
|
||||
ngx.say("failed to set keepalive: ", err)
|
||||
return
|
||||
end
|
||||
';
|
||||
--- response_body
|
||||
cmd 1:
|
||||
cmd 2: OK
|
||||
failed to run command 3: WRONGTYPE Operation against a key holding the wrong kind of value
|
||||
cmd 4: an animal
|
||||
--- no_error_log
|
||||
[error]
|
||||
929
src/deps/src/lua-resty-redis/t/pubsub.t
vendored
929
src/deps/src/lua-resty-redis/t/pubsub.t
vendored
|
|
@ -1,929 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use t::Test;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: single channel
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
local red2 = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
red2:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red2:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("2: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:subscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: subscribe: ", cjson.encode(res))
|
||||
|
||||
res, err = red2:publish("dog", "Hello")
|
||||
if not res then
|
||||
ngx.say("2: failed to publish: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("2: publish: ", cjson.encode(res))
|
||||
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
|
||||
red:close()
|
||||
red2:close()
|
||||
';
|
||||
--- response_body
|
||||
1: subscribe: ["subscribe","dog",1]
|
||||
2: publish: 1
|
||||
1: receive: ["message","dog","Hello"]
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: single channel (retry read_reply() after timeout)
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
lua_socket_log_errors off;
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
local red2 = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
red2:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red2:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("2: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:subscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: subscribe: ", cjson.encode(res))
|
||||
|
||||
red:set_timeout(1)
|
||||
for i = 1, 2 do
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
if err ~= "timeout" then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
red:set_timeout(1000)
|
||||
|
||||
res, err = red:unsubscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to unsubscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red2:publish("dog", "Hello")
|
||||
if not res then
|
||||
ngx.say("2: failed to publish: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("2: publish: ", cjson.encode(res))
|
||||
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:unsubscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to unsubscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
|
||||
red:close()
|
||||
red2:close()
|
||||
';
|
||||
--- response_body
|
||||
1: subscribe: ["subscribe","dog",1]
|
||||
1: failed to read reply: timeout
|
||||
1: failed to read reply: timeout
|
||||
1: unsubscribe: ["unsubscribe","dog",0]
|
||||
2: publish: 0
|
||||
1: failed to read reply: not subscribed
|
||||
1: failed to unsubscribe: not subscribed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: multiple channels
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
lua_socket_log_errors off;
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
local red2 = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
red2:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red2:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("2: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:subscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: subscribe dog: ", cjson.encode(res))
|
||||
|
||||
res, err = red:subscribe("cat")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: subscribe cat: ", cjson.encode(res))
|
||||
|
||||
res, err = red2:publish("dog", "Hello")
|
||||
if not res then
|
||||
ngx.say("2: failed to publish: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("2: publish: ", cjson.encode(res))
|
||||
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:set_timeout(10) -- 10ms
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
red:set_timeout(1000) -- 1s
|
||||
|
||||
res, err = red:unsubscribe()
|
||||
if not res then
|
||||
ngx.say("1: failed to unscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:set_timeout(10) -- 10ms
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
red:set_timeout(1000) -- 1s
|
||||
|
||||
red:close()
|
||||
red2:close()
|
||||
';
|
||||
--- response_body_like chop
|
||||
^1: subscribe dog: \["subscribe","dog",1\]
|
||||
1: subscribe cat: \["subscribe","cat",2\]
|
||||
2: publish: 1
|
||||
1: receive: \["message","dog","Hello"\]
|
||||
1: failed to read reply: timeout
|
||||
1: unsubscribe: \[\["unsubscribe","(?:cat|dog)",1\],\["unsubscribe","(?:cat|dog)",0\]\]
|
||||
1: failed to read reply: not subscribed
|
||||
1: failed to read reply: not subscribed$
|
||||
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 4: call subscribe after read_reply() times out
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
lua_socket_log_errors off;
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
local red2 = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
red2:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red2:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("2: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:subscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: subscribe: ", cjson.encode(res))
|
||||
|
||||
red:set_timeout(1)
|
||||
for i = 1, 2 do
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
if err ~= "timeout" then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
red:set_timeout(1000)
|
||||
|
||||
res, err = red:subscribe("cat")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe to cat: ", err)
|
||||
else
|
||||
ngx.say("1: subscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:close()
|
||||
red2:close()
|
||||
';
|
||||
--- response_body
|
||||
1: subscribe: ["subscribe","dog",1]
|
||||
1: failed to read reply: timeout
|
||||
1: failed to read reply: timeout
|
||||
1: subscribe: ["subscribe","cat",2]
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 5: call set_keepalive in subscribed mode (previous read_reply calls timed out)
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
lua_socket_log_errors off;
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
local red2 = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
red2:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red2:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("2: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:subscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: subscribe: ", cjson.encode(res))
|
||||
|
||||
red:set_timeout(1)
|
||||
for i = 1, 2 do
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
if err ~= "timeout" then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
red:set_timeout(1000)
|
||||
|
||||
res, err = red:set_keepalive()
|
||||
if not res then
|
||||
ngx.say("1: failed to set keepalive: ", err)
|
||||
else
|
||||
ngx.say("1: set keepalive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:close()
|
||||
red2:close()
|
||||
';
|
||||
--- response_body
|
||||
1: subscribe: ["subscribe","dog",1]
|
||||
1: failed to read reply: timeout
|
||||
1: failed to read reply: timeout
|
||||
1: failed to set keepalive: subscribed state
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 6: call set_keepalive in subscribed mode
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
lua_socket_log_errors off;
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
local red2 = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
red2:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red2:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("2: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:subscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: subscribe: ", cjson.encode(res))
|
||||
|
||||
res, err = red:set_keepalive()
|
||||
if not res then
|
||||
ngx.say("1: failed to set keepalive: ", err)
|
||||
else
|
||||
ngx.say("1: set keepalive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:close()
|
||||
red2:close()
|
||||
';
|
||||
--- response_body
|
||||
1: subscribe: ["subscribe","dog",1]
|
||||
1: failed to set keepalive: subscribed state
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 7: call set_keepalive in unsubscribed mode
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
lua_socket_log_errors off;
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
local red2 = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
red2:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red2:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("2: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:subscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: subscribe: ", cjson.encode(res))
|
||||
|
||||
res, err = red:unsubscribe()
|
||||
if not res then
|
||||
ngx.say("1: failed to unsubscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
|
||||
res, err = red:set_keepalive()
|
||||
if not res then
|
||||
ngx.say("1: failed to set keepalive: ", err)
|
||||
else
|
||||
ngx.say("1: set keepalive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:close()
|
||||
red2:close()
|
||||
';
|
||||
--- response_body
|
||||
1: subscribe: ["subscribe","dog",1]
|
||||
1: unsubscribe: ["unsubscribe","dog",0]
|
||||
1: set keepalive: 1
|
||||
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 8: mix read_reply and other commands
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
lua_socket_log_errors off;
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
local red2 = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
red2:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red2:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("2: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:subscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red2:publish("dog", "Hello")
|
||||
if not res then
|
||||
ngx.say("2: failed to publish: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:ping()
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red2:publish("dog", "World")
|
||||
if not res then
|
||||
ngx.say("2: failed to publish: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:unsubscribe()
|
||||
if not res then
|
||||
ngx.say("1: failed to unscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:set_timeout(1) -- 1s
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:close()
|
||||
red2:close()
|
||||
';
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body_like chop
|
||||
1: receive: \["message","dog","Hello"\]
|
||||
1: receive: \["message","dog","World"\]
|
||||
1: unsubscribe: \["unsubscribe","dog",0\]
|
||||
1: failed to read reply: not subscribed$
|
||||
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 9: multiple subscribe
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua_block {
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:subscribe("dog", "cat")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
else
|
||||
ngx.say("1: subscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:unsubscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to unsubscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:unsubscribe("cat")
|
||||
if not res then
|
||||
ngx.say("1: failed to unsubscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:close()
|
||||
}
|
||||
--- response_body
|
||||
1: subscribe: [["subscribe","dog",1],["subscribe","cat",2]]
|
||||
1: unsubscribe: ["unsubscribe","dog",1]
|
||||
1: unsubscribe: ["unsubscribe","cat",0]
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 10: multiple unsubscribe
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua_block {
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:subscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:subscribe("cat")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:unsubscribe()
|
||||
if not res then
|
||||
ngx.say("1: failed to unscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:close()
|
||||
}
|
||||
--- response_body_like
|
||||
^1: unsubscribe: \[\["unsubscribe","(?:cat|dog)",1\],\["unsubscribe","(?:cat|dog)",0\]\]$
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 11: multiple psubscribe
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua_block {
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:psubscribe("dog", "cat")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
else
|
||||
ngx.say("1: subscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:punsubscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to unsubscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:punsubscribe("cat")
|
||||
if not res then
|
||||
ngx.say("1: failed to unsubscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:close()
|
||||
}
|
||||
--- response_body
|
||||
1: subscribe: [["psubscribe","dog",1],["psubscribe","cat",2]]
|
||||
1: unsubscribe: ["punsubscribe","dog",1]
|
||||
1: unsubscribe: ["punsubscribe","cat",0]
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 12: multiple punsubscribe
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua_block {
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:psubscribe("dog")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:psubscribe("cat")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:punsubscribe()
|
||||
if not res then
|
||||
ngx.say("1: failed to unscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:close()
|
||||
}
|
||||
--- response_body_like
|
||||
^1: unsubscribe: \[\["punsubscribe","(?:cat|dog)",1\],\["punsubscribe","(?:cat|dog)",0\]\]$
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 13: mix read_reply, subscribe, and psubscribe
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua_block {
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local red = redis:new()
|
||||
local red2 = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
red2:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("1: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red2:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("2: failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:subscribe("two")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:psubscribe("t*o")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red2:publish("two", "foo")
|
||||
if not res then
|
||||
ngx.say("2: failed to publish: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red2:publish("too", "bar")
|
||||
if not res then
|
||||
ngx.say("2: failed to publish: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red2:publish("too", "baz")
|
||||
if not res then
|
||||
ngx.say("2: failed to publish: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:punsubscribe()
|
||||
if not res then
|
||||
ngx.say("1: failed to unscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
local res, err = red:subscribe("three")
|
||||
if not res then
|
||||
ngx.say("1: failed to subscribe: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red2:publish("three", "foo")
|
||||
if not res then
|
||||
ngx.say("2: failed to publish: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red2:publish("two", "bar")
|
||||
if not res then
|
||||
ngx.say("2: failed to publish: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
res, err = red:unsubscribe("three")
|
||||
if not res then
|
||||
ngx.say("1: failed to unscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:read_reply()
|
||||
if not res then
|
||||
ngx.say("1: failed to read reply: ", err)
|
||||
else
|
||||
ngx.say("1: receive: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
res, err = red:unsubscribe()
|
||||
if not res then
|
||||
ngx.say("1: failed to unscribe: ", err)
|
||||
else
|
||||
ngx.say("1: unsubscribe: ", cjson.encode(res))
|
||||
end
|
||||
|
||||
red:close()
|
||||
red2:close()
|
||||
}
|
||||
--- response_body_like chop
|
||||
^1: receive: \["p?message",("two"|"t\*o","two"),"foo"\]
|
||||
1: receive: \["p?message",("two"|"t\*o","two"),"foo"\]
|
||||
1: unsubscribe: \["punsubscribe","t\*o",1\]
|
||||
1: unsubscribe: \["unsubscribe","three",1\]
|
||||
1: receive: \["message","two","bar"\]
|
||||
1: unsubscribe: \["unsubscribe","two",0\]
|
||||
--- no_error_log
|
||||
[error]
|
||||
1051
src/deps/src/lua-resty-redis/t/sanity.t
vendored
1051
src/deps/src/lua-resty-redis/t/sanity.t
vendored
File diff suppressed because it is too large
Load diff
343
src/deps/src/lua-resty-redis/t/ssl.t
vendored
343
src/deps/src/lua-resty-redis/t/ssl.t
vendored
|
|
@ -1,343 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
use Test::Nginx::Socket::Lua;
|
||||
use Cwd qw(cwd);
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
|
||||
$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
|
||||
$ENV{TEST_NGINX_STREAM_REDIS_PORT} ||= 12345;
|
||||
|
||||
my $MainConfig = qq{
|
||||
stream {
|
||||
server {
|
||||
listen unix:$ENV{TEST_NGINX_HTML_DIR}/nginx.sock;
|
||||
listen unix:$ENV{TEST_NGINX_HTML_DIR}/nginx-ssl.sock ssl;
|
||||
listen 127.0.0.1:$ENV{TEST_NGINX_STREAM_REDIS_PORT} ssl;
|
||||
|
||||
ssl_certificate ../../cert/test.crt;
|
||||
ssl_certificate_key ../../cert/test.key;
|
||||
|
||||
proxy_pass 127.0.0.1:$ENV{TEST_NGINX_REDIS_PORT};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
my $pwd = cwd();
|
||||
my $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;;";
|
||||
};
|
||||
|
||||
add_block_preprocessor(sub {
|
||||
my $block = shift;
|
||||
|
||||
if (!defined $block->main_config) {
|
||||
$block->set_value("main_config", $MainConfig);
|
||||
}
|
||||
|
||||
if (!defined $block->http_config) {
|
||||
$block->set_value("http_config", $HttpConfig);
|
||||
}
|
||||
|
||||
if (!defined $block->request) {
|
||||
$block->set_value("request", "GET /t");
|
||||
}
|
||||
|
||||
if (!defined $block->no_error_log) {
|
||||
$block->set_value("no_error_log", "[error]");
|
||||
}
|
||||
});
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: ssl connection on non ssl server
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(100)
|
||||
|
||||
local ok, err = red:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock", {
|
||||
ssl = true
|
||||
})
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
failed to connect: failed to do ssl handshake: timeout
|
||||
|
||||
|
||||
|
||||
=== TEST 2: set and get on ssl connection
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000)
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_STREAM_REDIS_PORT, {
|
||||
ssl = true
|
||||
})
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red:select(1)
|
||||
if not ok then
|
||||
ngx.say("failed to select: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:set("dog", "an animal")
|
||||
if not res then
|
||||
ngx.say("failed to set dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("set dog: ", res)
|
||||
|
||||
for i = 1, 2 do
|
||||
local res, err = red:get("dog")
|
||||
if err then
|
||||
ngx.say("failed to get dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
if not res then
|
||||
ngx.say("dog not found.")
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("dog: ", res)
|
||||
end
|
||||
|
||||
red:close()
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
set dog: OK
|
||||
dog: an animal
|
||||
dog: an animal
|
||||
|
||||
|
||||
|
||||
=== TEST 3: set and get on ssl connection via unix socket
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000)
|
||||
|
||||
local ok, err = red:connect("unix:$TEST_NGINX_HTML_DIR/nginx-ssl.sock", {
|
||||
ssl = true
|
||||
})
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ok, err = red:select(1)
|
||||
if not ok then
|
||||
ngx.say("failed to select: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:set("dog", "an animal")
|
||||
if not res then
|
||||
ngx.say("failed to set dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("set dog: ", res)
|
||||
|
||||
for i = 1, 2 do
|
||||
local res, err = red:get("dog")
|
||||
if err then
|
||||
ngx.say("failed to get dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
if not res then
|
||||
ngx.say("dog not found.")
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("dog: ", res)
|
||||
end
|
||||
|
||||
red:close()
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
set dog: OK
|
||||
dog: an animal
|
||||
dog: an animal
|
||||
|
||||
|
||||
|
||||
=== TEST 4: ssl connection with ssl_verify (without CA)
|
||||
--- config
|
||||
lua_socket_log_errors off;
|
||||
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(100)
|
||||
|
||||
local ok, err = red:connect("unix:$TEST_NGINX_HTML_DIR/nginx-ssl.sock", {
|
||||
ssl = true,
|
||||
ssl_verify = true
|
||||
})
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
failed to connect: failed to do ssl handshake: 18: self signed certificate
|
||||
|
||||
|
||||
|
||||
=== TEST 5: ssl connection with ssl_verify (with CA)
|
||||
--- config
|
||||
lua_socket_log_errors off;
|
||||
lua_ssl_trusted_certificate ../../cert/test.crt;
|
||||
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(100)
|
||||
|
||||
local ok, err = red:connect("unix:$TEST_NGINX_HTML_DIR/nginx-ssl.sock", {
|
||||
ssl = true,
|
||||
ssl_verify = true
|
||||
})
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("ok")
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
ok
|
||||
|
||||
|
||||
|
||||
=== TEST 6: non-ssl connection to unix socket (issue #187)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(100)
|
||||
|
||||
local ok, err = red:connect("unix:$TEST_NGINX_HTML_DIR/nginx-ssl.sock")
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("ok")
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
ok
|
||||
|
||||
|
||||
|
||||
=== TEST 7: non-ssl connection to unix socket with second argument nil (issue #187)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(100)
|
||||
|
||||
local ok, err = red:connect("unix:$TEST_NGINX_HTML_DIR/nginx-ssl.sock",nil)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("ok")
|
||||
}
|
||||
}
|
||||
--- response_body
|
||||
ok
|
||||
|
||||
|
||||
|
||||
=== TEST 8: ssl reuse
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
red:set_timeout(1000)
|
||||
|
||||
local function connect_set(red)
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_STREAM_REDIS_PORT, {
|
||||
ssl = true
|
||||
})
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
ngx.say("sock reusetimes: ", red:get_reused_times())
|
||||
|
||||
ok, err = red:select(1)
|
||||
if not ok then
|
||||
ngx.say("failed to select: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:set("dog", "an animal")
|
||||
if not res then
|
||||
ngx.say("failed to set dog: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("set dog: ", res)
|
||||
|
||||
local ok, err = red:set_keepalive()
|
||||
if not ok then
|
||||
ngx.say("failed to set keepalive: ", err)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
connect_set(red)
|
||||
connect_set(red)
|
||||
}
|
||||
}
|
||||
--- response_body eval
|
||||
qr/sock reusetimes: (0|2)
|
||||
set dog: OK
|
||||
sock reusetimes: (1|3)
|
||||
set dog: OK/
|
||||
119
src/deps/src/lua-resty-redis/t/transaction.t
vendored
119
src/deps/src/lua-resty-redis/t/transaction.t
vendored
|
|
@ -1,119 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use t::Test;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: sanity
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local redis_key = "foo"
|
||||
|
||||
local ok, err = red:multi()
|
||||
if not ok then
|
||||
ngx.say("failed to run multi: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("multi ans: ", cjson.encode(ok))
|
||||
|
||||
local ans, err = red:sort("log", "by", redis_key .. ":*->timestamp")
|
||||
if not ans then
|
||||
ngx.say("failed to run sort: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("sort ans: ", cjson.encode(ans))
|
||||
|
||||
ans, err = red:exec()
|
||||
|
||||
ngx.say("exec ans: ", cjson.encode(ans))
|
||||
|
||||
local ok, err = red:set_keepalive(0, 1024)
|
||||
if not ok then
|
||||
ngx.say("failed to put the current redis connection into pool: ", err)
|
||||
return
|
||||
end
|
||||
';
|
||||
--- response_body
|
||||
multi ans: "OK"
|
||||
sort ans: "QUEUED"
|
||||
exec ans: [{}]
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: redis cmd reference sample: redis does not halt on errors
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local ok, err = red:multi()
|
||||
if not ok then
|
||||
ngx.say("failed to run multi: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("multi ans: ", cjson.encode(ok))
|
||||
|
||||
local ans, err = red:set("a", "abc")
|
||||
if not ans then
|
||||
ngx.say("failed to run sort: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("set ans: ", cjson.encode(ans))
|
||||
|
||||
local ans, err = red:lpop("a")
|
||||
if not ans then
|
||||
ngx.say("failed to run sort: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("set ans: ", cjson.encode(ans))
|
||||
|
||||
ans, err = red:exec()
|
||||
|
||||
ngx.say("exec ans: ", cjson.encode(ans))
|
||||
|
||||
red:close()
|
||||
';
|
||||
--- response_body_like chop
|
||||
^multi ans: "OK"
|
||||
set ans: "QUEUED"
|
||||
set ans: "QUEUED"
|
||||
exec ans: \["OK",\[false,"(?:ERR|WRONGTYPE) Operation against a key holding the wrong kind of value"\]\]
|
||||
$
|
||||
--- no_error_log
|
||||
[error]
|
||||
47
src/deps/src/lua-resty-redis/t/user-cmds.t
vendored
47
src/deps/src/lua-resty-redis/t/user-cmds.t
vendored
|
|
@ -1,47 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use t::Test;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: single channel
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local cjson = require "cjson"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
redis.add_commands("foo", "bar")
|
||||
|
||||
local red = redis:new()
|
||||
|
||||
red:set_timeout(1000) -- 1 sec
|
||||
|
||||
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local res, err = red:foo("a")
|
||||
if not res then
|
||||
ngx.say("failed to foo: ", err)
|
||||
end
|
||||
|
||||
res, err = red:bar()
|
||||
if not res then
|
||||
ngx.say("failed to bar: ", err)
|
||||
end
|
||||
';
|
||||
--- response_body eval
|
||||
qr/\Afailed to foo: ERR unknown command [`']foo[`'](?:, with args beginning with: `a`,\s*)?
|
||||
failed to bar: ERR unknown command [`']bar[`'](?:, with args beginning with:\s*)?
|
||||
\z/
|
||||
--- no_error_log
|
||||
[error]
|
||||
23
src/deps/src/lua-resty-redis/t/version.t
vendored
23
src/deps/src/lua-resty-redis/t/version.t
vendored
|
|
@ -1,23 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use t::Test;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: basic
|
||||
--- global_config eval: $::GlobalConfig
|
||||
--- server_config
|
||||
content_by_lua '
|
||||
local redis = require "resty.redis"
|
||||
ngx.say(redis._VERSION)
|
||||
';
|
||||
--- response_body_like chop
|
||||
^\d+\.\d+$
|
||||
--- no_error_log
|
||||
[error]
|
||||
Loading…
Reference in a new issue