Redis.Protocol.Coerce (Redis v0.8.0)

Copy Markdown View Source

Coerces RESP2 flat-list responses into RESP3-style types based on the command.

RESP3 natively returns HGETALL as a map and SMEMBERS as a set. RESP2 returns flat lists for both. This module bridges the gap so callers get consistent types regardless of protocol version.

Usage

result = Coerce.coerce(["f1", "v1", "f2", "v2"], "HGETALL")
#=> %{"f1" => "v1", "f2" => "v2"}

result = Coerce.coerce(["a", "b", "c"], "SMEMBERS")
#=> MapSet.new(["a", "b", "c"])

Summary

Functions

Coerces a RESP2 result based on the command name. Returns the result unchanged if no coercion applies.

Extracts the command name from a command list for coercion lookup.

Functions

coerce(result, command)

@spec coerce(term(), String.t()) :: term()

Coerces a RESP2 result based on the command name. Returns the result unchanged if no coercion applies.

command_name(arg1)

@spec command_name([String.t()]) :: String.t()

Extracts the command name from a command list for coercion lookup.