Interacting with Redis and frappe.cache in Frappe.
frappe.cache is a Redis wrapper that auto-prefixes keys with the current site name.
# Set with TTL (preferred for ephemeral state)
frappe.cache.set_value("presence:user1", {"status": "online"}, expires_in_sec=300)
# Set without TTL (persistent until cleared)
frappe.cache.set_value("config:feature_flags", {"beta": True})
# Get
value = frappe.cache.get_value("presence:user1")
# Delete
frappe.cache.delete_value("presence:user1")
# Delete multiple
frappe.cache.delete_value(["key1", "key2"])
Pass logical keys (e.g. presence:user1). The wrapper handles site-prefixing automatically. Do NOT manually prefix with database name.
# Get keys matching a prefix
keys = frappe.cache.get_keys("presence:")
# Count active keys
count = len(frappe.cache.get_keys("presence:"))
get_keys returns raw Redis keys (with site prefix). Safe for counting. Do NOT compare directly to unprefixed logical keys.
frappe.session or documents