return upstream status with srcache_fetch and subrequests

24 views
Skip to first unread message

sakir

unread,
Apr 17, 2024, 6:41:44 AMApr 17
to openresty-en
Hi,

I have the following configuration that uses srcache module, it works properly with returning 200 or 404 , HIT and MISS.

However, there are cases the upstream(redis) itself fails and it still returns 404. In the cases when the upstream has failed, I'd like to return an internal server error like 500 or 504. The reason is that, the depending services are assuming such key doesn't exist in Redis and continues to their operations, which is not correct.

I'd like to do that without needing to check the upstream one more time if possible, so I thought perhaps I can pass a variable from the subrequest to the request itself?

Thank you in advance!


location = /cache-fetch {
  internal;
  set $redis_key $query_string;
  redis_pass redis;
}
location /getvalue {
  srcache_store_skip 1;
  srcache_fetch GET /cache-fetch $key;
  echo_status 404;
}
Reply all
Reply to author
Forward
0 new messages