Bandera. Store. Persistent. Redis. Serializer
(bandera v0.1.0)
Copy Markdown
Pure mapping between Bandera.Gates and Redis hash {field, value} pairs.
The hash field is the gate id (Bandera.Gate.id/1), so both percentage gate
types share the "percentage" field (one percentage gate per flag — an HSET
overwrites it). The value encodes "true"/"false" for boolean/actor/group, or
"time/<ratio>"/"actors/<ratio>" for percentage gates.
Flag names read back are converted to atoms via String.to_atom/1 (supporting
listing flags created in a prior VM session). Flag names must therefore be a
bounded, developer-defined set — never untrusted user input.
Summary
Functions
Rebuilds a Bandera.Flag from a flat HGETALL reply (alternating field/value
entries).
Returns the Redis hash field for a gate (its id) — the hash key used to delete it.
Serializes a gate to the {field, value} pair stored in the flag's Redis hash.
Functions
@spec deserialize_flag(atom() | String.t(), [String.t()]) :: Bandera.Flag.t()
Rebuilds a Bandera.Flag from a flat HGETALL reply (alternating field/value
entries).
The flag name is converted to an atom, so it must be a bounded, developer-defined value — never untrusted input.
Examples
iex> flag = Bandera.Store.Persistent.Redis.Serializer.deserialize_flag(:my_flag, ["boolean", "true"])
iex> flag.name
:my_flag
iex> flag.gates
[%Bandera.Gate{type: :boolean, for: nil, enabled: true}]
@spec field(Bandera.Gate.t()) :: String.t()
Returns the Redis hash field for a gate (its id) — the hash key used to delete it.
Examples
iex> Bandera.Store.Persistent.Redis.Serializer.field(Bandera.Gate.new(:group, :beta, true))
"group/beta"
@spec serialize(Bandera.Gate.t()) :: {String.t(), String.t()}
Serializes a gate to the {field, value} pair stored in the flag's Redis hash.
The field is the gate id (so the percentage slot is shared); the value encodes the ratio for percentage gates and the boolean otherwise.
Examples
iex> Bandera.Store.Persistent.Redis.Serializer.serialize(Bandera.Gate.new(:boolean, true))
{"boolean", "true"}
iex> Bandera.Store.Persistent.Redis.Serializer.serialize(Bandera.Gate.new(:actor, "u1", true))
{"actor/u1", "true"}
iex> Bandera.Store.Persistent.Redis.Serializer.serialize(Bandera.Gate.new(:percentage_of_time, 0.5))
{"percentage", "time/0.5"}