Lux Docs

Build on Lux without guessing.

Lux Cloud + OSS core

Product docs for the Lux runtime: tables, cache, vectors, realtime, time series, auth, HTTP, SDK, CLI, and self-hosting.

Hashes

Hashes are maps of field-value pairs, ideal for representing objects. Each hash can store over 4 billion field-value pairs.

HSET / HGET / HDEL

Set one or more fields, retrieve a single field, or delete fields from a hash.

Syntax
HSET key field value [field value ...]
HGET key field
HDEL key field [field ...]
Example
> HSET user:1 name "alice" email "alice@example.com" age "30"
(integer) 3
> HGET user:1 name
"alice"
> HDEL user:1 age
(integer) 1

HGETALL / HKEYS / HVALS

Retrieve all fields and values, just the field names, or just the values from a hash.

Example
> HGETALL user:1
1) "name"
2) "alice"
3) "email"
4) "alice@example.com"
> HKEYS user:1
1) "name"
2) "email"
> HVALS user:1
1) "alice"
2) "alice@example.com"

HINCRBY / HINCRBYFLOAT

Atomically increment a hash field by an integer or float value. Creates the field with the increment as the value if it does not exist.

Example
> HSET product:1 views 0 price 9.99
(integer) 2
> HINCRBY product:1 views 1
(integer) 1
> HINCRBY product:1 views 5
(integer) 6
> HINCRBYFLOAT product:1 price 0.50
"10.49"

HMSET / HMGET

Set or get multiple fields in a single call. HMSET is functionally identical to HSET with multiple fields but remains available for compatibility.

Example
> HMSET config:app theme "dark" lang "en" tz "UTC"
OK
> HMGET config:app theme lang
1) "dark"
2) "en"

HEXISTS / HLEN / HSETNX

Check if a field exists, count total fields, or set a field only if it does not already exist.

Example
> HEXISTS user:1 name
(integer) 1
> HEXISTS user:1 phone
(integer) 0
> HLEN user:1
(integer) 2
> HSETNX user:1 name "bob"
(integer) 0
> HSETNX user:1 phone "555-1234"
(integer) 1

HSCAN

Incrementally iterate over fields and values in a hash. Use MATCH to filter by pattern and COUNT to hint at the number of elements to return per call.

Example
> HSCAN user:1 0 MATCH "e*" COUNT 10
1) "0"
2) 1) "email"
   2) "alice@example.com"

Command Reference

CommandDescription
HSETSet one or more field-value pairs
HGETGet the value of a field
HDELDelete one or more fields
HGETALLGet all fields and values
HKEYSGet all field names
HVALSGet all values
HLENGet the number of fields
HEXISTSCheck if a field exists
HINCRBYIncrement a field's integer value
HINCRBYFLOATIncrement a field's float value
HMSETSet multiple fields (same as HSET)
HMGETGet values of multiple fields
HSETNXSet a field only if it does not exist
HSTRLENGet the length of a field's value
HRANDFIELDReturn random fields from a hash
HSCANIncrementally iterate over fields