Class: Ask::State::Adapter
- Inherits:
-
Object
- Object
- Ask::State::Adapter
- Defined in:
- lib/ask/state.rb
Overview
Abstract base class for state backends. Subclasses must implement all methods.
Direct Known Subclasses
Instance Method Summary collapse
-
#acquire_lock(key, ttl: 10) ⇒ Lock?
Acquire a lock for a key.
-
#close ⇒ Object
Optional: called when the adapter is no longer needed.
- #delete(key) ⇒ Object
-
#dequeue(queue) ⇒ QueueEntry?
Pop the next item from a named queue.
-
#enqueue(queue, value) ⇒ QueueEntry
Push an item onto a named queue.
-
#get(key) ⇒ Object?
The stored value, or nil if not found.
-
#list_append(key, value, max_length: nil) ⇒ Object
Append a value to an ordered list.
-
#list_range(key, start = 0, stop = -1)) ⇒ Array<Object>
Return a slice of the list.
-
#list_remove(key, value) ⇒ Integer
Remove all occurrences of a value from a list.
-
#queue_depth(queue) ⇒ Integer
The number of items in the queue.
-
#release_lock(key, lock) ⇒ Boolean
Release a lock.
- #set(key, value, ttl: nil) ⇒ Object
-
#set_if_not_exists(key, value, ttl: nil) ⇒ Boolean
Atomically set a value only if the key does not already exist.
Instance Method Details
#acquire_lock(key, ttl: 10) ⇒ Lock?
Acquire a lock for a key. Returns nil if the lock is held by another owner.
82 83 84 |
# File 'lib/ask/state.rb', line 82 def acquire_lock(key, ttl: 10) raise NotImplementedError end |
#close ⇒ Object
Optional: called when the adapter is no longer needed.
147 148 149 |
# File 'lib/ask/state.rb', line 147 def close # no-op by default end |
#delete(key) ⇒ Object
64 65 66 |
# File 'lib/ask/state.rb', line 64 def delete(key) raise NotImplementedError end |
#dequeue(queue) ⇒ QueueEntry?
Pop the next item from a named queue.
107 108 109 |
# File 'lib/ask/state.rb', line 107 def dequeue(queue) raise NotImplementedError end |
#enqueue(queue, value) ⇒ QueueEntry
Push an item onto a named queue.
100 101 102 |
# File 'lib/ask/state.rb', line 100 def enqueue(queue, value) raise NotImplementedError end |
#get(key) ⇒ Object?
Returns the stored value, or nil if not found.
52 53 54 |
# File 'lib/ask/state.rb', line 52 def get(key) raise NotImplementedError end |
#list_append(key, value, max_length: nil) ⇒ Object
Append a value to an ordered list. Trims to max_length (keeps newest).
123 124 125 |
# File 'lib/ask/state.rb', line 123 def list_append(key, value, max_length: nil) raise NotImplementedError end |
#list_range(key, start = 0, stop = -1)) ⇒ Array<Object>
Return a slice of the list.
132 133 134 |
# File 'lib/ask/state.rb', line 132 def list_range(key, start = 0, stop = -1) raise NotImplementedError end |
#list_remove(key, value) ⇒ Integer
Remove all occurrences of a value from a list.
140 141 142 |
# File 'lib/ask/state.rb', line 140 def list_remove(key, value) raise NotImplementedError end |
#queue_depth(queue) ⇒ Integer
Returns the number of items in the queue.
113 114 115 |
# File 'lib/ask/state.rb', line 113 def queue_depth(queue) raise NotImplementedError end |
#release_lock(key, lock) ⇒ Boolean
Release a lock. Only the lock owner can release it.
90 91 92 |
# File 'lib/ask/state.rb', line 90 def release_lock(key, lock) raise NotImplementedError end |
#set(key, value, ttl: nil) ⇒ Object
59 60 61 |
# File 'lib/ask/state.rb', line 59 def set(key, value, ttl: nil) raise NotImplementedError end |
#set_if_not_exists(key, value, ttl: nil) ⇒ Boolean
Atomically set a value only if the key does not already exist.
72 73 74 |
# File 'lib/ask/state.rb', line 72 def set_if_not_exists(key, value, ttl: nil) raise NotImplementedError end |