Luis Henrique Dallelaste Bernartt
11/07/2025, 1:09 PMMarvin
11/07/2025, 1:09 PMMarvin
11/07/2025, 1:12 PMfrom redis.sentinel import Sentinel
from prefect import flow, task
def get_redis():
sentinels = [("sentinel-1", 26379), ("sentinel-2", 26379), ("sentinel-3", 26379)]
s = Sentinel(sentinels, socket_timeout=0.5) # add password/db kwargs if needed
return s.master_for("mymaster", decode_responses=True)
@task
def set_value(key, value):
r = get_redis()
r.set(key, value)
@task
def get_value(key):
r = get_redis()
return r.get(key)
@flow
def demo():
set_value("example", "42")
v = get_value("example")
print(v)
if __name__ == "__main__":
demo()
- If you want UI‑managed credentials like a Block, create a small custom Prefect block that stores Sentinel hosts and returns a redis.sentinel.Sentinel(...).master_for(...) client.
References:
- Prefect Redis integration overview: Prefect Redis integration
- Prefect custom blocks guide: Creating custom blocks
- redis‑py Sentinel docs: redis-py Sentinel
If you can share how you plan to use Redis with Prefect (caching, concurrency limits/leases, or general data ops), I can suggest the cleanest Sentinel-compatible setup or sketch a custom block for you.