Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentinel Example #52

Open
rsidhaarth opened this issue Mar 13, 2025 · 2 comments
Open

Sentinel Example #52

rsidhaarth opened this issue Mar 13, 2025 · 2 comments

Comments

@rsidhaarth
Copy link

Hi,

Is it possible for you to add sentinel example in readme as I could not able to get it work.

Thanks

@rsidhaarth
Copy link
Author

`vcl 4.1;

import redis;

backend default {
.host = "127.0.0.1";
.port = "8080";
}

sub vcl_init {
redis.sentinels(
locations="10.10.20.41:26379,10.10.20.42:26379,10.10.20.43:26379",
period=60,
connection_timeout=500
);

new db = redis.db(
    location="mymaster",
    type=auto,
    connection_timeout=500,
    shared_connections=true,
    max_connections=128
);

}

sub vcl_recv {
redis.use("db");

if (req.http.X-Redis-Key) {
    set req.http.redis-key = req.http.X-Redis-Key;
} else {
    set req.http.redis-key = "failover-test-key";
}

db.command("SET");
db.push(req.http.redis-key);
db.push("Test value from Varnish Redis Sentinel failover check");
db.execute(true);

db.command("GET");
db.push(req.http.redis-key);
db.execute(false);
set req.http.redis-value = db.get_string_reply();

return (synth(200, "Redis Sentinel Failover Test OK"));

}

sub vcl_synth {
set resp.http.X-Redis-Key = req.http.redis-key;
set resp.http.X-Redis-Value = req.http.redis-value;
set resp.http.X-Redis-Stats = db.stats();
}
`

We could not able to set key, can you help in this?

@carlosabalde
Copy link
Owner

Hi @rsidhaarth! It looks like you're assuming using Sentinel you can auto-discover master and slave instances, but that's not how the VMOD works (see #38). The VMOD integrates with Redis Sentinel it order to find the new master when a failover occurs, but that's all. The list of Redis Server instances needs to be explicitly specified. I hope this helps! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants