【发布时间】:2021-08-02 17:07:45
【问题描述】:
我的 VCL:
vcl 4.1;
import redis;
import std;
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "2015";
}
sub vcl_init {
# VMOD configuration: simple case, keeping up to one Redis connection
# per Varnish worker thread.
new db = redis.db(
location="127.0.0.1:6379",
type=master,
connection_timeout=500,
shared_connections=false,
max_connections=1);
db.command("SET");
db.push("foo");
db.push("10s");
db.execute();
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc
unset req.http.Cookie;
}
sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
if ( bereq.url ~ " \.(ts|m3u8)$") {
unset beresp.http.set-cookie;
# set beresp.http.cache-control = "public, max-age=259200";
db.command("GET");
db.push("foo");
db.execute(false);
std.log("HERE" + db.get_string_reply());
set beresp.ttl = std.duration(db.get_string_reply(), 60s);
return (pass);
}
}
sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}
我正在尝试使用 redis vmod。
问题:如您所见,我已使用 redis 将 ttl 逻辑放入 vcl 中。 但是每当我点击 url 时,varnish 总是在内容上使用 120 秒的默认 ttl。
我做错了什么?
【问题讨论】:
标签: varnish