Skip to content

Commit adea034

Browse files
committed
added tests for combining ngx_srcache with ngx_redis/ngx_redis2.
1 parent fa2da58 commit adea034

File tree

2 files changed

+130
-1
lines changed

2 files changed

+130
-1
lines changed

t/redis.t

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# vi:ft=
2+
3+
use lib 'lib';
4+
use Test::Nginx::Socket;
5+
6+
#repeat_each(2);
7+
8+
plan tests => repeat_each() * 5 * blocks();
9+
10+
$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
11+
12+
#master_on();
13+
#no_long_string();
14+
no_shuffle();
15+
16+
run_tests();
17+
18+
__DATA__
19+
20+
=== TEST 1: flush all
21+
--- config
22+
location /flush {
23+
redis2_query flushall;
24+
redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
25+
}
26+
--- response_headers
27+
Content-Type: text/plain
28+
!Content-Length
29+
--- request
30+
GET /flush
31+
--- response_body eval: "+OK\r\n"
32+
--- no_error_log
33+
[error]
34+
35+
36+
37+
=== TEST 2: basic fetch (cache miss)
38+
--- timeout: 3
39+
--- config
40+
location /foo {
41+
default_type text/css;
42+
43+
set $key $uri;
44+
set_escape_uri $escaped_key $key;
45+
srcache_fetch GET /redis $key;
46+
srcache_store POST /redis2 key=$escaped_key&exptime=120;
47+
48+
echo hello;
49+
echo hiya;
50+
}
51+
52+
location = /redis {
53+
internal;
54+
55+
set $redis_key $args;
56+
redis_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
57+
}
58+
59+
location = /redis2 {
60+
internal;
61+
62+
set_unescape_uri $exptime $arg_exptime;
63+
set_unescape_uri $key $arg_key;
64+
65+
redis2_query set $key $echo_request_body;
66+
redis2_query expire $key $exptime;
67+
redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
68+
}
69+
--- request
70+
GET /foo
71+
--- response_headers
72+
Content-Type: text/css
73+
!Content-Length
74+
--- response_body
75+
hello
76+
hiya
77+
--- no_error_log
78+
[error]
79+
80+
81+
82+
=== TEST 3: basic fetch (cache hit)
83+
--- config
84+
location /foo {
85+
default_type text/css;
86+
87+
set $key $uri;
88+
srcache_fetch GET /redis $key;
89+
srcache_store PUT /redis2 key=$key&exptime=10;
90+
91+
echo world;
92+
}
93+
94+
location = /redis {
95+
#internal;
96+
97+
#redis2_query get $args;
98+
#redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
99+
#echo "args = $args";
100+
101+
set $redis_key $args;
102+
redis_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
103+
}
104+
105+
location = /redis2 {
106+
internal;
107+
108+
set_unescape_uri $exptime $arg_exptime;
109+
set_unescape_uri $key $arg_key;
110+
111+
redis2_query set $key $echo_request_body;
112+
redis2_query expire $key $exptime;
113+
114+
redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
115+
}
116+
--- request
117+
GET /foo
118+
--- response_headers
119+
Content-Type: text/css
120+
Content-Length: 11
121+
--- response_body
122+
hello
123+
hiya
124+
--- no_error_log
125+
[error]
126+

util/build.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ ngx-build $force $version \
2020
--without-http_autoindex_module \
2121
--without-http_auth_basic_module \
2222
--without-http_userid_module \
23+
--add-module=$root/../ndk-nginx-module \
24+
--add-module=$root/../set-misc-nginx-module \
25+
--add-module=$home/work/nginx/ngx_http_redis-0.3.5 \
2326
--add-module=$root/../xss-nginx-module \
27+
--add-module=$root/../redis2-nginx-module \
2428
--add-module=$root/../eval-nginx-module \
2529
--add-module=$root/../echo-nginx-module \
2630
--add-module=$root/../headers-more-nginx-module \
@@ -30,7 +34,6 @@ ngx-build $force $version \
3034
--add-module=$root/../drizzle-nginx-module \
3135
--add-module=$root/../postgres-nginx-module \
3236
--add-module=$root/../memc-nginx-module \
33-
--add-module=$root/../ndk-nginx-module \
3437
--with-select_module \
3538
--with-poll_module \
3639
--with-rtsig_module \

0 commit comments

Comments
 (0)