Manages type metadata for Redis keys that hold data structures.
When a key is first used as a hash, list, set, or sorted set, a type metadata entry is written to the same Bitcask shard:
T:keyname -> "hash" | "list" | "set" | "zset"Subsequent commands check this metadata and return a WRONGTYPE error if the command's expected type does not match. String keys do NOT get a type entry -- only data structure keys do. This matches Redis behavior where string operations on a data structure key return WRONGTYPE.
Type Enforcement
The check_or_set/3 function either:
- Sets the type if the key has no type yet (first use)
- Returns
:okif the key already has the expected type - Returns
{:error, wrongtype_message}if the type mismatches
Summary
Functions
Checks that redis_key has the expected type, or sets it if the key
has no type metadata yet.
Checks that a key either does not exist or has the expected type, WITHOUT setting the type if it doesn't exist. Used for read-only operations that should not create keys.
Removes the type metadata for a Redis key.
Returns the type of a Redis key, or nil if no type metadata exists.
Functions
@spec check_or_set(binary(), Ferricstore.Store.CompoundKey.data_type(), map()) :: :ok | {:error, binary()}
Checks that redis_key has the expected type, or sets it if the key
has no type metadata yet.
Parameters
redis_key- the Redis key to checktype- the expected data type (:hash,:list,:set,:zset)store- the store (Instance, LocalTxStore, or closure map)
Returns
:okif the type matches or was newly set{:error, wrongtype_message}if the type mismatches
@spec check_type(binary(), Ferricstore.Store.CompoundKey.data_type(), map()) :: :ok | {:error, binary()}
Checks that a key either does not exist or has the expected type, WITHOUT setting the type if it doesn't exist. Used for read-only operations that should not create keys.
Returns
:okif the key doesn't exist or has the expected type{:error, wrongtype_message}if the type mismatches
Removes the type metadata for a Redis key.
Called when DEL removes a data structure key.
Parameters
redis_key- the Redis key whose type to removestore- the store (Instance, LocalTxStore, or closure map)
Returns the type of a Redis key, or nil if no type metadata exists.
Used by the TYPE command.
Parameters
redis_key- the Redis key to look upstore- the store (Instance, LocalTxStore, or closure map)
Returns
"hash","list","set","zset","string", or"none"