Permalink
Browse files

bugfix: directives redis2_query, redis2_literal_raw_query, and redis2…

…_raw_queries could not be inherited automatically by the "location if" blocks, resulting in the "no redis2 query specified or the query is empty" errors. thanks Tomasz Prus for the patch in github pull #14.
  • Loading branch information...
1 parent 9d52f17 commit 8e80fcff47763750026d11fb35d1bbf642eee3bb @agentzh agentzh committed Aug 29, 2012
Showing with 106 additions and 0 deletions.
  1. +13 −0 src/ngx_http_redis2_module.c
  2. +93 −0 t/if.t
@@ -229,6 +229,19 @@ ngx_http_redis2_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->complex_query = prev->complex_query;
}
+ if (conf->complex_query_count == NULL) {
+ conf->complex_query_count = prev->complex_query_count;
+ }
+
+ if (conf->queries == NULL) {
+ conf->queries = prev->queries;
+ }
+
+ if (conf->literal_query.data == NULL) {
+ conf->literal_query.data = prev->literal_query.data;
+ conf->literal_query.len = prev->literal_query.len;
+ }
+
return NGX_CONF_OK;
}
View
@@ -0,0 +1,93 @@
+# vi:ft=
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+#repeat_each(2);
+
+plan tests => repeat_each() * (3 * blocks());
+
+$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
+
+#master_on;
+#worker_connections 1024;
+
+#no_diff;
+no_long_string;
+
+#log_level 'warn';
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: location if (query)
+--- config
+ location /redis {
+ set $key 'default';
+ if ($uri ~ "(special.*)") {
+ set $key $1;
+ }
+ redis2_query lrange $key 0 -1;
+ redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
+ }
+--- request
+ GET /redis/special
+--- response_body eval
+"*0\r\n"
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: location if (literal query)
+--- config
+ location /redis {
+ if ($uri ~ "(special.*)") {
+ }
+ redis2_literal_raw_query 'flushall\r\n';
+ redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
+ }
+--- request
+ GET /redis/special
+--- response_body eval
+"+OK\r\n"
+--- no_error_log
+[error]
+
+
+
+=== TEST 3: location if (raw queries)
+--- config
+ location /redis {
+ if ($uri ~ "(special.*)") {
+ set $n 2;
+ }
+ redis2_raw_queries $n 'flushall\r\nget foo\r\n';
+ redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
+ }
+--- request
+ GET /redis/special
+--- response_body eval
+"+OK\r\n\$-1\r\n"
+--- no_error_log
+[error]
+
+
+
+=== TEST 4: location if (raw query)
+--- config
+ location /redis {
+ if ($uri ~ "(special.*)") {
+ set $n 2;
+ }
+ redis2_raw_query 'flushall\r\n';
+ redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
+ }
+--- request
+ GET /redis/special
+--- response_body eval
+"+OK\r\n"
+--- no_error_log
+[error]
+

0 comments on commit 8e80fcf

Please sign in to comment.