cabol / nebulex_redis_adapter

Nebulex adapter for Redis

Home Page:https://hexdocs.pm/nebulex_redis_adapter/NebulexRedisAdapter.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Configurable codec to encode/decode Redis keys and values

cabol opened this issue · comments

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