SuperCache.Queue (SuperCache v1.3.0)

Copy Markdown View Source

Named FIFO queues backed by SuperCache ETS partitions.

Works transparently in both local and distributed modes — the mode is determined by the :cluster option passed to SuperCache.start!/1.

In distributed mode, structural mutations (add, out, get_all) are routed to the partition's primary node. Reads (peak, count) default to the local replica and accept :read_mode for stronger consistency.

Example

alias SuperCache.Queue

Queue.add("jobs", :compress)
Queue.add("jobs", :upload)
Queue.count("jobs")          # => 2
Queue.peak("jobs")           # => :compress
Queue.out("jobs")            # => :compress
Queue.get_all("jobs")        # => [:upload]

Summary

Functions

Enqueue value into queue_name. Creates the queue if it does not exist.

Return the number of items.

Drain all items (oldest first). Returns [] for an empty queue.

Dequeue and return the front value. Returns default (nil) when empty.

Peek at the front value without removing it.

Functions

add(queue_name, value)

@spec add(any(), any()) :: true

Enqueue value into queue_name. Creates the queue if it does not exist.

count(queue_name, opts \\ [])

@spec count(
  any(),
  keyword()
) :: non_neg_integer()

Return the number of items.

Options

  • :read_mode:local (default), :primary, or :quorum.

get_all(queue_name)

@spec get_all(any()) :: list()

Drain all items (oldest first). Returns [] for an empty queue.

out(queue_name, default \\ nil)

@spec out(any(), any()) :: any()

Dequeue and return the front value. Returns default (nil) when empty.

peak(queue_name, default \\ nil, opts \\ [])

@spec peak(any(), any(), keyword()) :: any()

Peek at the front value without removing it.

Options

  • :read_mode:local (default), :primary, or :quorum.