Reference

SQL & Redis

SQLite, PostgreSQL, Snowflake and Redis syntax, queries and everyday operations.

Scope and conventions

SQL examples name their database and assume the sample schema where indicated. Redis examples are native redis-cli commands, with optional Search/JSON features labeled. Run independent examples in your own scratch database; driver binding syntax and transaction guarantees differ.

Expiration & operations

Iterate keys without one complete blocking listing

Redis

SCAN returns a next cursor and a batch. Start at 0 and continue with each returned cursor until it returns 0 again. COUNT is a hint, not a fixed page size; batches can be empty and keys can repeat. Changing data has limited iteration guarantees. Avoid treating SCAN as deterministic result pagination.

Fragment

Redis · Iterate keys without one complete blocking listing
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
SCAN 0 MATCH ref:* COUNT 20
# Continue with the cursor returned by the server.
# HSCAN/SSCAN/ZSCAN iterate one collection.

Native commands in one redis-cli session; # lines are explanatory, not commands. Examples use disposable ref:* keys.

Inspect expiration, persistence and missing replies

Redis

EXPIRE uses seconds; PEXPIRE milliseconds. TTL returns remaining seconds, -1 for an existing key without expiry and -2 for a missing key. PERSIST removes expiry. Expiration, memory-pressure eviction and durable recovery are different mechanisms; cache absence must be expected by its caller.

Fragment

Redis · Inspect expiration, persistence and missing replies
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
SET ref:session active EX 60
TTL ref:session
PERSIST ref:session
TTL ref:session
EXISTS ref:session

Native commands in one redis-cli session; # lines are explanatory, not commands. Examples use disposable ref:* keys.

Recognize the connection and name scope

Redis

redis-cli sends native commands to a server. Prefixes are a key-naming convention, not relational schemas or automatic ACL isolation. SELECT chooses a logical database where supported; Redis Cluster uses database 0.

Fragment

Redis · Recognize the connection and name scope
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
redis-cli
# Inside the session:
# PING
# TYPE ref:items:1

Shell command plus commented interactive commands. No connection secrets are embedded.

Recognize an export versus a recoverable backup

Redis

DUMP serializes one value into a binary payload, while PTTL reads its remaining lifetime separately. It is not a whole-database backup, and a text terminal is not a binary-safe transport. Use the documented persistence/backup workflow for recovery, then verify restored data.

Fragment

Redis · Recognize an export versus a recoverable backup
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
PTTL ref:items:1
DUMP ref:items:1

Native commands in one redis-cli session; # lines are explanatory, not commands. Examples use disposable ref:* keys.

Inspect tables, columns and indexes

Redis

TYPE reports the native kind of a key; OBJECT and MEMORY expose selected metadata. Redis keys do not imply a relational table schema.

Fragment

Redis · Inspect tables, columns and indexes
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
TYPE ref:items:1
MEMORY USAGE ref:items:1

Native commands in redis-cli; explanatory # lines are not commands. Replace observed-ID placeholders and use disposable ref:* keys.

Create and restore a named scratch backup

Redis

redis-cli --rdb can obtain an RDB snapshot using the replication protocol. Restoration is an offline server/data-directory procedure, not a RESTORE command for the whole database.

Fragment

Redis · Create and restore a named scratch backup
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
redis-cli --rdb snapshot.rdb

Requires appropriate access and a compatible persistence/recovery procedure. Include configuration/ACL and other required state in your recovery plan; test in a separate instance.

Inspect Redis memory, persistence and slow commands

Redis

INFO sections expose server counters/state; MEMORY USAGE estimates a chosen key’s memory. SLOWLOG records server command execution duration, excluding client/network time. Current observations are not a complete history.

Fragment

Redis · Inspect Redis memory, persistence and slow commands
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
INFO memory
INFO persistence
INFO stats
MEMORY USAGE ref:items:1
SLOWLOG GET 5

Native commands in redis-cli; explanatory # lines are not commands. Replace observed-ID placeholders and use disposable ref:* keys.