FerricStore (ferricstore v0.11.4)

Copy Markdown View Source

Module-based cache instances for FerricStore.

Each module that calls use FerricStore gets a local direct cache instance with its own shards, ETS tables, data directory, and config. The default application instance owns the Raft system.

Usage

defmodule MyApp.Cache do
  use FerricStore,
    data_dir: "/data/cache",
    shard_count: 4,
    max_memory: "1GB"
end

# In your supervision tree:
children = [MyApp.Cache]

# Then use it:
MyApp.Cache.set("key", "value")
{:ok, "value"} = MyApp.Cache.get("key")

Multiple instances

defmodule MyApp.Sessions do
  use FerricStore,
    data_dir: "/data/sessions",
    shard_count: 2
end

MyApp.Cache.set("page:home", html)
MyApp.Sessions.set("sess:abc", session_data)

Options

  • :data_dir — base directory for Bitcask data files (required)
  • :shard_count — number of shards (default: 4)
  • :max_memory_bytes — maximum memory budget (default: 1GB)
  • :keydir_max_ram — maximum ETS keydir memory (default: 256MB)
  • :eviction_policy:volatile_lfu | :allkeys_lfu | :noeviction (default: :volatile_lfu)

  • :hot_cache_max_value_size — max value size for ETS caching (default: 65536)
  • :read_sample_rate — LFU sampling rate (default: 100)
  • :flow_retention_sweeper — per-instance Flow timeout/retention sweeper
  • :flow_scheduler — per-instance durable schedule runner options such as :initial_delay_ms, :error_sleep_ms, and :limit

Summary

Functions

Blocks until FerricStore is fully ready to serve requests.

See FerricStore.API.Generic.dbsize/0.

See FerricStore.API.System.echo/1.

See FerricStore.API.Flow.flow_approval_approve/2.

See FerricStore.API.Flow.flow_approval_get/2.

See FerricStore.API.Flow.flow_approval_list/1.

See FerricStore.API.Flow.flow_approval_reject/2.

See FerricStore.API.Flow.flow_approval_request/2.

See FerricStore.API.Flow.flow_attribute_values/3.

See FerricStore.API.Flow.flow_attributes/2.

See FerricStore.API.Flow.flow_budget_commit/4.

See FerricStore.API.Flow.flow_budget_get/2.

See FerricStore.API.Flow.flow_budget_list/1.

See FerricStore.API.Flow.flow_budget_release/3.

See FerricStore.API.Flow.flow_budget_reserve/3.

See FerricStore.API.Flow.flow_by_correlation/2.

See FerricStore.API.Flow.flow_by_parent/2.

See FerricStore.API.Flow.flow_by_root/2.

See FerricStore.API.Flow.flow_cancel/2.

See FerricStore.API.Flow.flow_cancel_many/3.

See FerricStore.API.Flow.flow_circuit_close/2.

See FerricStore.API.Flow.flow_circuit_get/2.

See FerricStore.API.Flow.flow_circuit_list/1.

See FerricStore.API.Flow.flow_circuit_open/2.

See FerricStore.API.Flow.flow_claim_due/2.

See FerricStore.API.Flow.flow_complete/3.

See FerricStore.API.Flow.flow_complete_many/3.

See FerricStore.API.Flow.flow_create/2.

See FerricStore.API.Flow.flow_create_many/3.

See FerricStore.API.Flow.flow_effect_compensate/3.

See FerricStore.API.Flow.flow_effect_confirm/3.

See FerricStore.API.Flow.flow_effect_fail/3.

See FerricStore.API.Flow.flow_effect_get/3.

See FerricStore.API.Flow.flow_effect_reserve/4.

See FerricStore.API.Flow.flow_extend_lease/3.

See FerricStore.API.Flow.flow_fail/3.

See FerricStore.API.Flow.flow_fail_many/3.

See FerricStore.API.Flow.flow_failures/2.

See FerricStore.API.Flow.flow_get/2.

See FerricStore.API.Flow.flow_governance_ledger/2.

See FerricStore.API.Flow.flow_governance_overview/1.

See FerricStore.API.Flow.flow_history/2.

See FerricStore.API.Flow.flow_info/2.

See FerricStore.API.Flow.flow_limit_get/2.

See FerricStore.API.Flow.flow_limit_lease/2.

See FerricStore.API.Flow.flow_limit_list/1.

See FerricStore.API.Flow.flow_limit_release/2.

See FerricStore.API.Flow.flow_limit_spend/2.

See FerricStore.API.Flow.flow_list/2.

See FerricStore.API.Flow.flow_policy_get/2.

See FerricStore.API.Flow.flow_policy_set/2.

See FerricStore.API.Flow.flow_query/2.

See FerricStore.API.Flow.flow_reclaim/2.

See FerricStore.API.Flow.flow_retention_cleanup/1.

See FerricStore.API.Flow.flow_retry/3.

See FerricStore.API.Flow.flow_retry_many/3.

See FerricStore.API.Flow.flow_rewind/2.

See FerricStore.API.Flow.flow_run_steps_many/2.

See FerricStore.API.Flow.flow_schedule_create/2.

See FerricStore.API.Flow.flow_schedule_delete/2.

See FerricStore.API.Flow.flow_schedule_fire/2.

See FerricStore.API.Flow.flow_schedule_fire_due/1.

See FerricStore.API.Flow.flow_schedule_get/2.

See FerricStore.API.Flow.flow_schedule_list/1.

See FerricStore.API.Flow.flow_schedule_pause/2.

See FerricStore.API.Flow.flow_schedule_resume/2.

See FerricStore.API.Flow.flow_search/1.

See FerricStore.API.Flow.flow_signal/2.

See FerricStore.API.Flow.flow_spawn_children/3.

See FerricStore.API.Flow.flow_start_and_claim/4.

See FerricStore.API.Flow.flow_stats/2.

See FerricStore.API.Flow.flow_step_continue/5.

See FerricStore.API.Flow.flow_stuck/2.

See FerricStore.API.Flow.flow_terminals/2.

See FerricStore.API.Flow.flow_transition/4.

See FerricStore.API.Flow.flow_transition_many/5.

See FerricStore.API.Flow.flow_value_mget/2.

See FerricStore.API.Flow.flow_value_put/2.

See FerricStore.API.System.flushall/0.

See FerricStore.API.Generic.flushdb/0.

Returns the current health status without blocking.

See FerricStore.API.Generic.keys/1.

See FerricStore.API.System.multi/1.

See FerricStore.API.System.packed_batch_get/1.

See FerricStore.API.System.ping/0.

See FerricStore.API.System.pipeline/1.

See FerricStore.API.Generic.randomkey/0.

Returns true if FerricStore is ready to serve requests.

Gracefully shuts down FerricStore, flushing all pending data to disk.

Types

cas_opts()

@type cas_opts() :: [{:ttl, non_neg_integer()}]

fetch_or_compute_opts()

@type fetch_or_compute_opts() :: [ttl: pos_integer(), hint: binary()]

get_opts()

@type get_opts() :: [{:cache, atom()}]

key()

@type key() :: binary()

set_opts()

@type set_opts() :: [
  ttl: non_neg_integer(),
  exat: pos_integer(),
  pxat: pos_integer(),
  nx: boolean(),
  xx: boolean(),
  get: boolean(),
  keepttl: boolean(),
  cache: atom()
]

value()

@type value() :: binary()

write_error()

@type write_error() :: {:error, binary() | {:timeout, :unknown_outcome}}

zrange_opts()

@type zrange_opts() :: [{:withscores, boolean()}]

Functions

append(key, suffix)

await_ready(opts \\ [])

@spec await_ready(keyword()) :: :ok

Blocks until FerricStore is fully ready to serve requests.

Polls Health.check/0 until all shards are alive and all Raft leaders are elected. Returns :ok when ready, raises on timeout.

Call this in your application's start/2 after FerricStore is in your supervision tree, or in test setup, to ensure writes won't fail.

Options

  • :timeout - max milliseconds to wait (default: 30_000)
  • :interval - polling interval in ms (default: 100)

Examples

# In your Application.start/2:
def start(_type, _args) do
  children = [
    {FerricStore, []},
    MyApp.Repo,
    MyAppWeb.Endpoint
  ]
  opts = [strategy: :one_for_one, name: MyApp.Supervisor]
  {:ok, pid} = Supervisor.start_link(children, opts)

  FerricStore.await_ready()
  {:ok, pid}
end

# With custom timeout:
FerricStore.await_ready(timeout: 60_000)

batch_get(keys)

batch_set(kv_pairs)

@spec batch_set([{binary(), binary()}]) :: [:ok | write_error()] | write_error()

bf_add(key, element)

bf_card(key)

bf_exists(key, element)

bf_info(key)

bf_madd(key, elements)

bf_mexists(key, elements)

bf_reserve(key, error_rate, capacity)

bitcount(key, opts \\ [])

bitop(op, dest_key, source_keys)

bitpos(key, bit_value, opts \\ [])

cas(key, expected, new_value, opts \\ [])

cf_add(key, element)

cf_addnx(key, element)

cf_count(key, element)

cf_del(key, element)

cf_exists(key, element)

cf_info(key)

cf_mexists(key, elements)

cf_reserve(key, capacity)

cms_incrby(key, pairs)

cms_info(key)

cms_initbydim(key, width, depth)

cms_initbyprob(key, error, probability)

cms_query(key, elements)

copy(source, destination, opts \\ [])

dbsize()

See FerricStore.API.Generic.dbsize/0.

decr(key)

decr_by(key, amount)

del(key)

echo(message)

See FerricStore.API.System.echo/1.

exists(key)

expire(key, ttl_ms)

expireat(key, unix_ts_seconds)

expiretime(key)

extend(key, owner, ttl_ms)

fetch_or_compute(key, opts)

fetch_or_compute_error(key, message, opts)

fetch_or_compute_result(key, value, opts)

flow_approval_approve(id, opts \\ [])

See FerricStore.API.Flow.flow_approval_approve/2.

flow_approval_get(id, opts \\ [])

See FerricStore.API.Flow.flow_approval_get/2.

flow_approval_list(opts \\ [])

See FerricStore.API.Flow.flow_approval_list/1.

flow_approval_reject(id, opts \\ [])

See FerricStore.API.Flow.flow_approval_reject/2.

flow_approval_request(id, opts \\ [])

See FerricStore.API.Flow.flow_approval_request/2.

flow_attribute_values(type, attr_name, opts \\ [])

See FerricStore.API.Flow.flow_attribute_values/3.

flow_attributes(type, opts \\ [])

See FerricStore.API.Flow.flow_attributes/2.

flow_budget_commit(scope, reservation_id, actual_amount, opts \\ [])

See FerricStore.API.Flow.flow_budget_commit/4.

flow_budget_get(scope, opts \\ [])

See FerricStore.API.Flow.flow_budget_get/2.

flow_budget_list(opts \\ [])

See FerricStore.API.Flow.flow_budget_list/1.

flow_budget_release(scope, reservation_id, opts \\ [])

See FerricStore.API.Flow.flow_budget_release/3.

flow_budget_reserve(scope, amount, opts \\ [])

See FerricStore.API.Flow.flow_budget_reserve/3.

flow_by_correlation(correlation_id, opts \\ [])

See FerricStore.API.Flow.flow_by_correlation/2.

flow_by_parent(parent_flow_id, opts \\ [])

See FerricStore.API.Flow.flow_by_parent/2.

flow_by_root(root_flow_id, opts \\ [])

See FerricStore.API.Flow.flow_by_root/2.

flow_cancel(id, opts \\ [])

See FerricStore.API.Flow.flow_cancel/2.

flow_cancel_many(partition_key, items, opts \\ [])

See FerricStore.API.Flow.flow_cancel_many/3.

flow_circuit_close(scope, opts \\ [])

See FerricStore.API.Flow.flow_circuit_close/2.

flow_circuit_get(scope, opts \\ [])

See FerricStore.API.Flow.flow_circuit_get/2.

flow_circuit_list(opts \\ [])

See FerricStore.API.Flow.flow_circuit_list/1.

flow_circuit_open(scope, opts \\ [])

See FerricStore.API.Flow.flow_circuit_open/2.

flow_claim_due(type, opts)

See FerricStore.API.Flow.flow_claim_due/2.

flow_complete(id, lease_token, opts \\ [])

See FerricStore.API.Flow.flow_complete/3.

flow_complete_many(partition_key, items, opts \\ [])

See FerricStore.API.Flow.flow_complete_many/3.

flow_create(id, opts)

See FerricStore.API.Flow.flow_create/2.

flow_create_many(partition_key, items, opts \\ [])

See FerricStore.API.Flow.flow_create_many/3.

flow_effect_compensate(id, effect_key, opts \\ [])

See FerricStore.API.Flow.flow_effect_compensate/3.

flow_effect_confirm(id, effect_key, opts \\ [])

See FerricStore.API.Flow.flow_effect_confirm/3.

flow_effect_fail(id, effect_key, opts \\ [])

See FerricStore.API.Flow.flow_effect_fail/3.

flow_effect_get(id, effect_key, opts \\ [])

See FerricStore.API.Flow.flow_effect_get/3.

flow_effect_reserve(id, effect_key, effect_type, opts \\ [])

See FerricStore.API.Flow.flow_effect_reserve/4.

flow_extend_lease(id, lease_token, opts \\ [])

See FerricStore.API.Flow.flow_extend_lease/3.

flow_fail(id, lease_token, opts \\ [])

See FerricStore.API.Flow.flow_fail/3.

flow_fail_many(partition_key, items, opts \\ [])

See FerricStore.API.Flow.flow_fail_many/3.

flow_failures(type, opts \\ [])

See FerricStore.API.Flow.flow_failures/2.

flow_get(id, opts \\ [])

See FerricStore.API.Flow.flow_get/2.

flow_governance_ledger(id, opts \\ [])

See FerricStore.API.Flow.flow_governance_ledger/2.

flow_governance_overview(opts \\ [])

See FerricStore.API.Flow.flow_governance_overview/1.

flow_history(id, opts \\ [])

See FerricStore.API.Flow.flow_history/2.

flow_info(type, opts \\ [])

See FerricStore.API.Flow.flow_info/2.

flow_limit_get(scope, opts \\ [])

See FerricStore.API.Flow.flow_limit_get/2.

flow_limit_lease(scope, opts \\ [])

See FerricStore.API.Flow.flow_limit_lease/2.

flow_limit_list(opts \\ [])

See FerricStore.API.Flow.flow_limit_list/1.

flow_limit_release(scope, opts \\ [])

See FerricStore.API.Flow.flow_limit_release/2.

flow_limit_spend(scope, opts \\ [])

See FerricStore.API.Flow.flow_limit_spend/2.

flow_list(type, opts \\ [])

See FerricStore.API.Flow.flow_list/2.

flow_policy_get(type, opts \\ [])

See FerricStore.API.Flow.flow_policy_get/2.

flow_policy_set(type, opts)

See FerricStore.API.Flow.flow_policy_set/2.

flow_query(query, params \\ %{})

See FerricStore.API.Flow.flow_query/2.

flow_reclaim(type, opts)

See FerricStore.API.Flow.flow_reclaim/2.

flow_retention_cleanup(opts \\ [])

See FerricStore.API.Flow.flow_retention_cleanup/1.

flow_retry(id, lease_token, opts)

See FerricStore.API.Flow.flow_retry/3.

flow_retry_many(partition_key, items, opts \\ [])

See FerricStore.API.Flow.flow_retry_many/3.

flow_rewind(id, opts)

See FerricStore.API.Flow.flow_rewind/2.

flow_run_steps_many(items, opts \\ [])

See FerricStore.API.Flow.flow_run_steps_many/2.

flow_schedule_create(id, opts)

See FerricStore.API.Flow.flow_schedule_create/2.

flow_schedule_delete(id, opts \\ [])

See FerricStore.API.Flow.flow_schedule_delete/2.

flow_schedule_fire(id, opts \\ [])

See FerricStore.API.Flow.flow_schedule_fire/2.

flow_schedule_fire_due(opts \\ [])

See FerricStore.API.Flow.flow_schedule_fire_due/1.

flow_schedule_get(id, opts \\ [])

See FerricStore.API.Flow.flow_schedule_get/2.

flow_schedule_list(opts \\ [])

See FerricStore.API.Flow.flow_schedule_list/1.

flow_schedule_pause(id, opts \\ [])

See FerricStore.API.Flow.flow_schedule_pause/2.

flow_schedule_resume(id, opts \\ [])

See FerricStore.API.Flow.flow_schedule_resume/2.

flow_search(opts \\ [])

See FerricStore.API.Flow.flow_search/1.

flow_signal(id, opts)

See FerricStore.API.Flow.flow_signal/2.

flow_spawn_children(parent_id, children, opts \\ [])

See FerricStore.API.Flow.flow_spawn_children/3.

flow_start_and_claim(id, type, initial_state, opts \\ [])

See FerricStore.API.Flow.flow_start_and_claim/4.

flow_stats(type, opts \\ [])

See FerricStore.API.Flow.flow_stats/2.

flow_step_continue(id, lease_token, from_state, to_state, opts \\ [])

See FerricStore.API.Flow.flow_step_continue/5.

flow_stuck(type, opts \\ [])

See FerricStore.API.Flow.flow_stuck/2.

flow_terminals(type, opts \\ [])

See FerricStore.API.Flow.flow_terminals/2.

flow_transition(id, from_state, to_state, opts \\ [])

See FerricStore.API.Flow.flow_transition/4.

flow_transition_many(partition_key, from_state, to_state, items, opts \\ [])

See FerricStore.API.Flow.flow_transition_many/5.

flow_value_mget(refs, opts \\ [])

See FerricStore.API.Flow.flow_value_mget/2.

flow_value_put(value, opts \\ [])

See FerricStore.API.Flow.flow_value_put/2.

flushall()

@spec flushall() :: :ok | {:error, term()}

See FerricStore.API.System.flushall/0.

flushdb()

See FerricStore.API.Generic.flushdb/0.

geoadd(key, members)

geodist(key, member1, member2, unit \\ "m")

geohash(key, members)

geopos(key, members)

get(key, opts \\ [])

getbit(key, offset)

getdel(key)

getex(key, opts \\ [])

getrange(key, start, stop)

getset(key, value)

hdel(key, fields)

health()

@spec health() :: Ferricstore.Health.health_result()

Returns the current health status without blocking.

Examples

iex> FerricStore.health()
%{status: :ok, shard_count: 4, shards: [...], uptime_seconds: 120}

hexists(key, field)

hget(key, field)

hgetall(key)

hincrby(key, field, amount)

hincrbyfloat(key, field, amount)

hkeys(key)

hlen(key)

hmget(key, fields)

hrandfield(key, count \\ nil)

hset(key, fields)

hsetnx(key, field, value)

hstrlen(key, field)

hvals(key)

incr(key)

incr_by(key, amount)

incr_by_float(key, amount)

keys(pattern \\ "*")

See FerricStore.API.Generic.keys/1.

lindex(key, index)

linsert(key, direction, pivot, element)

llen(key)

lmove(source, destination, from_dir, to_dir)

lock(key, owner, ttl_ms)

lpop(key, count \\ 1)

lpos(key, element, opts \\ [])

lpush(key, elements)

lrange(key, start, stop)

lrem(key, count, element)

lset(key, index, element)

mget(keys)

mset(pairs)

msetnx(pairs)

multi(fun)

See FerricStore.API.System.multi/1.

packed_batch_get(packed_keys)

See FerricStore.API.System.packed_batch_get/1.

persist(key)

pexpire(key, ttl_ms)

pexpireat(key, unix_ts_ms)

pexpiretime(key)

pfadd(key, elements)

pfcount(keys)

pfmerge(dest_key, source_keys)

ping()

See FerricStore.API.System.ping/0.

pipeline(fun)

See FerricStore.API.System.pipeline/1.

psetex(key, milliseconds, value)

pttl(key)

randomkey()

See FerricStore.API.Generic.randomkey/0.

ratelimit_add(key, window_ms, max, count \\ 1)

ready?()

@spec ready?() :: boolean()

Returns true if FerricStore is ready to serve requests.

Examples

iex> FerricStore.ready?()
true

rename(source, destination)

renamenx(source, destination)

rpop(key, count \\ 1)

rpush(key, elements)

sadd(key, members)

scard(key)

sdiff(keys)

sdiffstore(destination, keys)

set(key, value, opts \\ [])

@spec set(key(), value(), set_opts()) ::
  :ok | {:ok, value() | nil} | nil | write_error()

setbit(key, offset, bit_value)

setex(key, seconds, value)

setnx(key, value)

setrange(key, offset, value)

shutdown()

@spec shutdown() :: :ok

Gracefully shuts down FerricStore, flushing all pending data to disk.

Flushes Raft batchers, BitcaskWriters, shard pending writes, and triggers a WAL rollover. Call before stopping the application to ensure zero data loss.

Examples

FerricStore.shutdown()
Application.stop(:ferricstore)

sinter(keys)

sintercard(keys, opts \\ [])

sinterstore(destination, keys)

sismember(key, member)

smembers(key)

smismember(key, members)

spop(key, count \\ nil)

srandmember(key, count \\ nil)

srem(key, members)

strlen(key)

sunion(keys)

sunionstore(destination, keys)

tdigest_add(key, values)

tdigest_byrank(key, ranks)

tdigest_byrevrank(key, ranks)

tdigest_cdf(key, values)

tdigest_create(key)

tdigest_info(key)

tdigest_max(key)

tdigest_min(key)

tdigest_quantile(key, quantiles)

tdigest_rank(key, values)

tdigest_reset(key)

tdigest_revrank(key, values)

tdigest_trimmed_mean(key, lo, hi)

topk_add(key, elements)

topk_info(key)

topk_list(key)

topk_query(key, elements)

topk_reserve(key, k)

ttl(key)

type(key)

unlock(key, owner)

xadd(key, fields)

xlen(key)

xrange(key, start, stop, opts \\ [])

xrevrange(key, stop, start, opts \\ [])

xtrim(key, opts)

zadd(key, score_member_pairs)

zcard(key)

zcount(key, min, max)

zincrby(key, increment, member)

zmscore(key, members)

zpopmax(key, count \\ 1)

zpopmin(key, count \\ 1)

zrandmember(key, count \\ nil)

zrange(key, start, stop, opts \\ [])

zrangebyscore(key, min, max, opts \\ [])

zrank(key, member)

zrem(key, members)

zrevrank(key, member)

zscore(key, member)