Configurable codec to encode/decode Redis keys and values
cabol opened this issue · comments
Carlos Andres Bolaños R.A. commented
Currently, the adapter encodes and decodes Redis keys and values automatically underneath, it encodes any Elixir term to a binary and decodes binaries into Elixir terms. The idea is to allow the user to optionally provide a custom codec with the option :codec
. The value must be a module implementing the NebulexRedisAdapter.Codec
behaviour.
This is how the behaviour may look like:
defmodule NebulexRedisAdapter.Codec do
@moduledoc """
Codec interface.
"""
@doc """
Encodes `key` with the given `opts`.
"""
@callback encode_key(key :: term, opts :: [term]) :: iodata
@doc """
Encodes `value` with the given `opts`.
"""
@callback encode_value(value :: term, opts :: [term]) :: iodata
@doc """
Decodes `key` with the given `opts`.
"""
@callback decode_key(key :: binary, opts :: [term]) :: term
@doc """
Decodes `value` with the given `opts`.
"""
@callback decode_value(value :: binary, opts :: [term]) :: term
end