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.

Analytical models

Recognize a transformation model and its dependencies

Redis

A Redis key/function pipeline does not execute a dbt SQL model. If a project publishes analytical results to Redis, the transformation tool, publication step, authoritative store and cache freshness each need their own contract.

Different native mechanism; no interchangeable statement is implied.

Different native mechanism; no interchangeable operation is implied.

Recognize incremental processing and data checks

Redis

A cached analytical answer needs an update/invalidation policy and observable freshness metadata. A key TTL is not proof that the value reflects recent source data; an incremental publisher must handle replays, corrections and partial failures deliberately.

Different native mechanism; no interchangeable statement is implied.

Different native mechanism; no interchangeable operation is implied.

Bucket events into a daily time series

Redis

Redis time series (bundled in Redis 8) store timestamped samples under one key. TS.RANGE with AGGREGATION groups samples into fixed buckets measured in milliseconds; 86400000 is one UTC day. EMPTY also reports buckets with no samples. Bucket boundaries are aligned to the Unix epoch by default (ALIGN changes that), so these buckets are UTC days, not local calendar days. In practice: use a time series for metrics and counters you query by range, and keep RETENTION bounded so old samples expire.

Fragment

Redis · Bucket events into a daily time series
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
TS.CREATE ref:signups RETENTION 7776000000 LABELS kind signup
# 2026-10-01 09:15, 2026-10-01 17:40 and 2026-10-03 08:05 UTC, in ms:
TS.ADD ref:signups 1790846100000 1
TS.ADD ref:signups 1790876400000 1
TS.ADD ref:signups 1791014700000 1
TS.RANGE ref:signups - + AGGREGATION count 86400000 EMPTY
# buckets: 1790812800000 -> 2, 1790899200000 -> 0, 1790985600000 -> 1

Native commands in one redis-cli session (Redis 8+, which bundles Search, JSON and time series; earlier versions need the matching modules). # lines are explanatory, not commands. Examples use disposable ref:* keys.