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.

Writing & parameters

Insert records with explicit columns

Redis

HSET creates or updates named hash fields. SET replaces an entire string value; SET ... NX writes only when the key does not exist. These commands do not validate a relational record or automatically populate relationship sets.

Fragment

Redis · Insert records with explicit columns
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
HSET ref:items:4 item_id 4 name Folder category paper qty 3 price 2.00
SET ref:claim "owner-a" NX

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

Update or delete the intended records

Redis

HINCRBY changes one numeric hash field; HSET replaces selected fields. HDEL removes fields, while DEL/UNLINK removes complete keys. Deleting a source key does not automatically remove separately maintained application references.

Fragment

Redis · Update or delete the intended records
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
HINCRBY ref:items:1 qty 1
HDEL ref:items:1 category
DEL ref:items:2

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

Declare a conflict or merge policy

Redis

HSET overwrites named fields, while HSETNX changes a field only if it is absent. SET NX/XX chooses key-existence conditions for strings. A revision-aware multi-field change needs WATCH/retry or a bounded server script; naming it “upsert” does not supply that policy.

Fragment

Redis · Declare a conflict or merge policy
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
HSETNX ref:items:1 qty 4
SET ref:state ready XX

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

Bind values without building query syntax

Redis

Native clients send command arguments separately; they do not require SQL string interpolation. Search PARAMS binds values inside its own query syntax with DIALECT 2+. It does not make arbitrary field names or query fragments safe.

Fragment

Redis · Bind values without building query syntax
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
FT.SEARCH ref:items "@qty:[$minimum +inf]" PARAMS 2 minimum 1 RETURN 2 item_id name DIALECT 2

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

Recognize a schema change

Redis

Redis has no table-schema ALTER. Evolve record fields, key formats and Search index definitions deliberately, preserving old readers and partially migrated records. Updating a hash field does not migrate every record or validate a common schema.

Different native mechanism; no interchangeable statement is implied.

Different native mechanism; no interchangeable operation is implied.