Module: Ask::State

Defined in:
lib/ask/state.rb

Overview

Pluggable state backend for agent sessions, channel providers, and any other ask-rb component that needs durable key-value storage, distributed locking, message queues, or ordered lists.

The Adapter abstract base defines the contract. Memory provides an in-process implementation backed by Hash. Production apps can provide Redis, PostgreSQL, or other backends by subclassing Adapter.

Examples:

Using the in-memory adapter

store = Ask::State::Memory.new
store.set("key", "value")
store.get("key")     # => "value"
store.delete("key")

Acquiring a distributed lock

lock = store.acquire_lock("resource-1", ttl: 10)
if lock
  begin
    # critical section
  ensure
    store.release_lock("resource-1", lock)
  end
end

Using a message queue

store.enqueue("queue-name", { task: "check_health" })
entry = store.dequeue("queue-name")
# => { id: "uuid", value: { task: "check_health" }, enqueued_at: timestamp }

Defined Under Namespace

Classes: Adapter, Lock, Memory, QueueEntry