Ferricstore.Commands.Generic (ferricstore v0.3.6)

Copy Markdown View Source

Handles Redis generic key commands: TYPE, UNLINK, RENAME, RENAMENX, COPY, RANDOMKEY, SCAN, EXPIRETIME, PEXPIRETIME, OBJECT, WAIT.

These commands operate on keys regardless of value type. Each handler takes the uppercased command name, a list of string arguments, and an injected store map. Returns plain Elixir terms -- the connection layer handles RESP encoding.

Supported commands

  • TYPE key -- returns the type of key ("string" for existing, "none" for missing)
  • UNLINK key [key ...] -- async DEL; returns count of deleted keys
  • RENAME key newkey -- rename key, error if source missing
  • RENAMENX key newkey -- rename only if newkey doesn't exist (1 = renamed, 0 = not)
  • COPY source destination [REPLACE] -- copy value+TTL (1 = success, 0 = failure)
  • RANDOMKEY -- return a random key, or nil if DB is empty
  • SCAN cursor [MATCH pattern] [COUNT count] [TYPE type] -- cursor-based key iteration
  • EXPIRETIME key -- absolute Unix timestamp (seconds) when key expires (-1 / -2)
  • PEXPIRETIME key -- absolute Unix timestamp (milliseconds) when key expires (-1 / -2)
  • OBJECT ENCODING key -- returns actual encoding based on key type
  • OBJECT HELP -- returns list of OBJECT subcommands
  • OBJECT FREQ key -- returns decayed LFU access frequency counter
  • OBJECT IDLETIME key -- returns idle seconds derived from LFU ldt
  • OBJECT REFCOUNT key -- always returns 1
  • WAIT numreplicas timeout -- returns 0 immediately (no replication)

Summary

Functions

Handles a generic key command.

Functions

handle(cmd, args, store)

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

Handles a generic key command.

Parameters

  • cmd - Uppercased command name (e.g. "TYPE", "RENAME")
  • args - List of string arguments
  • store - Injected store map with get, get_meta, put, delete, exists?, keys callbacks

Returns

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