1# vi:ft= 2 3use lib 'lib'; 4use Test::Nginx::Socket; 5 6#repeat_each(2); 7 8plan tests => repeat_each() * (3 * blocks()); 9 10$ENV{TEST_NGINX_REDIS_PORT} ||= 6379; 11 12#master_on; 13#worker_connections 1024; 14 15#no_diff; 16no_long_string; 17 18#log_level 'warn'; 19 20run_tests(); 21 22__DATA__ 23 24=== TEST 1: 0 in bulk size 25--- config 26 location /set { 27 redis2_query set 'counters::stats::list' '[["mafiaclans.eu", 12], ["picfu.net", 5], ["www.test.com", 0], ["www.ayom.com", 0], ["www.21dezember2012.org", 0], ["the-indie.ch", 0], ["spiele-check.de", 0], ["online-right-now.net", 0], ["google.com", 0]]'; 28 29 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 30 } 31 32 location /get { 33 redis2_raw_query 'get counters::stats::list\r\n'; 34 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 35 } 36 37 location /main2 { 38 content_by_lua ' 39 local res = ngx.location.capture("/set"); 40 ngx.print(res.body) 41 res = ngx.location.capture("/get"); 42 ngx.print(res.body) 43 '; 44 } 45 location /main { 46 # echo_location is buggy...sigh. 47 echo_location /set; 48 echo_location /get; 49 } 50--- request 51 GET /main2 52--- response_body eval 53qq{+OK\r 54\$207\r 55[["mafiaclans.eu", 12], ["picfu.net", 5], ["www.test.com", 0], ["www.ayom.com", 0], ["www.21dezember2012.org", 0], ["the-indie.ch", 0], ["spiele-check.de", 0], ["online-right-now.net", 0], ["google.com", 0]]\r 56} 57--- no_error_log 58[error] 59 60 61 62=== TEST 2: "0" digit in bulk count number 63--- config 64 location /set { 65 redis2_query set a hello; 66 67 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 68 } 69 70 location /get { 71 redis2_query mget a a a a a a a a a a; 72 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 73 } 74 75 location /main { 76 content_by_lua ' 77 local res = ngx.location.capture("/set"); 78 ngx.print(res.body) 79 res = ngx.location.capture("/get"); 80 ngx.print(res.body) 81 '; 82 } 83--- request 84 GET /main 85--- response_body eval 86qq{+OK\r 87\*10\r 88} . "\$5\r 89hello\r 90" x 10 91--- no_error_log 92[error] 93 94 95 96=== TEST 3: zero bulk count 97--- config 98 location /set { 99 redis2_query flushall; 100 101 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 102 } 103 104 location /get { 105 redis2_query lrange blah 0 0; 106 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 107 } 108 109 location /main { 110 content_by_lua ' 111 local res = ngx.location.capture("/set"); 112 ngx.print(res.body) 113 res = ngx.location.capture("/get"); 114 ngx.print(res.body) 115 '; 116 } 117--- request 118 GET /main 119--- response_body eval 120qq{+OK\r 121\*0\r 122} 123--- no_error_log 124[error] 125 126 127 128=== TEST 4: \r\n in content: sanity check 129--- config 130 location /set { 131 redis2_query set A 'hello\r\nworld'; 132 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 133 } 134 135 location /get { 136 redis2_query get A; 137 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 138 } 139 140 location /main { 141 content_by_lua ' 142 local res = ngx.location.capture("/set"); 143 ngx.print(res.body) 144 res = ngx.location.capture("/get"); 145 ngx.print(res.body) 146 '; 147 } 148--- request 149 GET /main 150--- response_body eval 151qq{+OK\r 152\$12\r 153hello\r 154world\r 155} 156--- no_error_log 157[error] 158 159 160 161=== TEST 5: github issue #5: Get content from Redis with "\r\n" in text fails with "Redis server returned extra bytes 162--- config 163 location /set { 164 redis2_query flushall; 165 redis2_query hset "/step2redisallhget?auctionid=2l" "content" "a 1line \r\n and 2nd"; 166 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 167 } 168 169 location /get { 170 redis2_query hget "/step2redisallhget?auctionid=2l" "content"; 171 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 172 } 173 174 location /main { 175 content_by_lua ' 176 local res = ngx.location.capture("/set"); 177 ngx.print(res.body) 178 res = ngx.location.capture("/get"); 179 ngx.print(res.body) 180 '; 181 } 182--- request 183 GET /main 184--- response_body eval 185qq{+OK\r 186:1\r 187\$18\r\na 1line \r\n and 2nd\r 188} 189--- no_error_log 190[error] 191 192 193 194=== TEST 6: set empty param 195--- config 196 location /set { 197 redis2_query flushall; 198 redis2_query set foo ""; 199 redis2_query get foo; 200 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 201 } 202--- request 203 GET /set 204--- response_body eval 205qq{+OK\r 206+OK\r 207\$0\r 208\r 209} 210--- no_error_log 211[error] 212 213 214 215=== TEST 7: two pipelined multi-bulk replies 216--- config 217 location /set { 218 redis2_query subscribe foo; 219 redis2_query unsubscribe foo; 220 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 221 } 222--- request 223 GET /set 224--- response_body eval 225qq{*3\r 226\$9\r 227subscribe\r 228\$3\r 229foo\r 230:1\r 231*3\r 232\$11\r 233unsubscribe\r 234\$3\r 235foo\r 236:0\r 237} 238--- no_error_log 239[error] 240 241 242 243=== TEST 8: empty multi-bulk replies 244--- config 245 location /set { 246 redis2_query flushall; 247 redis2_query blpop key 1; 248 redis2_query set key 3; 249 redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; 250 } 251--- request 252 GET /set 253--- response_body eval 254qq{+OK\r 255*-1\r 256+OK\r 257} 258--- timeout: 5 259--- no_error_log 260[error] 261 262