Hello
For some reason I cannot get the srcache module to work well with HttpRedis2Module module on a redis cluster. srcache works well with HttpRedisModule and HttpRedis2Module on a single redis node (the HttpRedisModule doesn't work with a redis cluster using set_hashed_upstream, sadly)
I am using OpenResty 1.2.7.1 and Redis 2.6.11. I am trying to cache my backend server JSON responses.
The urls I am calling are like:
http://api.dev:9090/collections/511193ba839e376d42913319/items
http://api.dev:9090/collections?edition=us&collection=home
I keep getting errors like this when I try to fetch
2013/03/21 08:56:12 [error] 9951#0: *1 srcache_fetch: cache sent invalid status line while sending to client, client: 127.0.0.1, server: api.*, request: "GET /collections?edition=us&collection=home HTTP/1.1", subrequest: "/redis-get", upstream: "redis2://127.0.0.1:6379", host: "api.dev:9090"
2013/03/21 09:11:09 [error] 9951#0: *10 srcache_fetch: cache sent truncated response body while sending to client, client: 127.0.0.1, server: api.*, request: "GET /collections/511193ba839e376d42913319/items HTTP/1.1", subrequest: "/redis-get", upstream: "redis2://127.0.0.1:6379", host: "api.dev:9090"
My nginx config is as follows:
daemon off;
pid {{scratch_directory}}/nginx.pid;
error_log {{scratch_directory}}/nginx_error.log;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream api_server {
server 127.0.0.1:8001;
}
upstream redis_tesla {
server 127.0.0.1:6379;
keepalive 512;
}
upstream redis_leaf {
server 127.0.0.1:6380;
keepalive 512;
}
upstream_list redis_cluster redis_tesla redis_leaf;
proxy_read_timeout 120;
proxy_connect_timeout 120;
server {
listen 9090;
client_max_body_size 10M;
server_name api.*;
access_log {{scratch_directory}}/api_access.log;
error_log {{scratch_directory}}/api_error.log;
location / {
if ($request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
proxy_redirect off;
# Send appropriate headers through
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
rewrite ^/api/dev/(.*)$ /$1 break;
# set expiration headers for site calls to be short
expires +120s;
# Only cache valid HTTP responses
srcache_store_statuses 200 301 302;
# only allow pull methods
srcache_methods GET HEAD;
set $key $request_method$request_uri;
set_escape_uri $escaped_key $key;
srcache_fetch GET /redis-get key=$escaped_key;
srcache_store PUT /redis-set key=$escaped_key&exptime=300;
proxy_pass http://api_server;
}
location = /redis-get {
internal;
set_unescape_uri $key $arg_key;
redis2_query get $key;
set_hashed_upstream $backend redis_cluster $key;
redis2_pass $backend;
}
location = /redis-set {
internal;
set_unescape_uri $exptime $arg_exptime;
set_unescape_uri $key $arg_key;
set_hashed_upstream $backend redis_cluster $key;
redis2_query set $key $echo_request_body;
redis2_query expire $key $exptime;
redis2_pass $backend;
}
# block common, unnecessary requests
location /favicon.ico {
access_log off;
error_log off;
log_not_found off;
deny all;
}
location /robots.txt {
access_log off;
error_log off;
log_not_found off;
deny all;
}
}
}
Any help would be greatly appreciated.
Thanks
-Diptamay