Ferricstore.Commands.Hash (ferricstore v0.3.6)

Copy Markdown View Source

Handles Redis hash commands: HSET, HGET, HDEL, HMGET, HGETALL, HLEN, HEXISTS, HKEYS, HVALS, HSETNX, HINCRBY, HINCRBYFLOAT, HEXPIRE, HTTL, HPERSIST, HSCAN, HRANDFIELD.

Each hash field is stored as an individual compound key entry in the shared shard Bitcask:

H:redis_key\0field_name -> value

This allows individual field access without reading or deserializing the entire hash. HGETALL scans all entries matching the hash prefix.

Hash Field TTL (Redis 7.4+)

Individual hash fields can have per-field expiry via HEXPIRE, HTTL, and HPERSIST. The expiry is stored as the expire_at_ms timestamp on each compound key entry.

Type Enforcement

All hash commands check the type metadata for the key. If the key already exists as a different data type (list, set, zset), a WRONGTYPE error is returned.

Summary

Functions

Handles a hash command.

Functions

handle(cmd, args, store)

@spec handle(binary(), [binary()], map()) :: term()

Handles a hash command.

Parameters

  • cmd - Uppercased command name (e.g. "HSET", "HGET")
  • args - List of string arguments
  • store - Injected store map with compound key callbacks

Returns

Plain Elixir term: integer, string, list, nil, or {:error, message}.