Key Commands¶
delete / unlink¶
r.delete("a", "b", "c") # synchronous delete, returns count
r.unlink("a", "b", "c") # async delete (non-blocking), returns count
Tip
Prefer unlink for large keys — it deletes in the background without blocking the server.
exists¶
expire / pexpire / expireat¶
r.expire("key", 60) # expire in 60 seconds
r.pexpire("key", 5000) # expire in 5000 milliseconds
r.expireat("key", 1700000000) # expire at Unix timestamp
ttl / pttl / persist¶
r.ttl("key") # seconds remaining, -1 if no expiry, -2 if missing
r.pttl("key") # milliseconds remaining
r.persist("key") # remove expiry
rename¶
type¶
keys / scan¶
Warning
keys blocks the server and scans all keys. Use scan for production.
cursor, keys = r.scan(0, match_pattern="user:*", count=100)
while cursor != "0":
cursor, more_keys = r.scan(cursor, match_pattern="user:*", count=100)
keys.extend(more_keys)
Note
Unlike redis-py, the cursor is returned as a string ("0" when done), not an integer.