RedixSandbox (redix_sandbox v0.1.0)

Copy Markdown View Source

Process-scoped Redis connections for concurrent tests.

Start a named sandbox with start_link/1, then check out that sandbox in each test with checkout/1. Redis commands use the {:via, RedixSandbox, name} tuple to resolve to the calling test's connection.

Summary

Functions

Allows a process to use the calling owner's checked-out Redis connection.

Checks out a Redis connection for the calling process.

Returns a specification to start this module under a supervisor.

Changes the ownership mode of a sandbox.

Starts a named sandbox.

Types

mode()

@type mode() :: :private | {:shared, pid()}

name()

@type name() :: atom()

Functions

allow(name, owner, child)

@spec allow(name(), pid(), pid()) ::
  :ok | {:error, RedixSandbox.Errors.AllowError.t()}

Allows a process to use the calling owner's checked-out Redis connection.

The owner must already have checked out the sandbox. The child shares the owner's logical Redis database.

checkout(name)

@spec checkout(name()) :: :ok | {:error, RedixSandbox.Errors.CheckoutError.t()}

Checks out a Redis connection for the calling process.

The pool implementation will reserve a logical Redis DB, flush it, and record the calling process as its owner before returning :ok. Failures return a RedixSandbox.Errors.CheckoutError with the sandbox, database when applicable, operation, and original reason.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

mode(name, arg2)

@spec mode(name(), mode()) :: :ok | {:error, RedixSandbox.Errors.ModeError.t()}

Changes the ownership mode of a sandbox.

In shared mode, the owner must already have checked out the sandbox and all callers resolve that owner's Redis connection. Use :private to restore process isolation.

register_name(name, pid)

@spec register_name(name(), pid()) :: :no

send(name, message)

@spec send(name(), term()) :: term()

start_link(options)

@spec start_link(keyword()) :: Supervisor.on_start()

Starts a named sandbox.

Each sandbox owns its Redix connections and NimbleOwnership server.

unregister_name(name)

@spec unregister_name(name()) :: :ok

whereis_name(sandbox)

@spec whereis_name(name()) :: pid()