-
Notifications
You must be signed in to change notification settings - Fork 67
Litequeue Guide
Litequeue is a simple and efficient queueing system for Ruby applications. This guide covers how to use Litequeue for creating queues, adding, and removing values.
To start using Litequeue, you first need to create an instance of the Litequeue class. You can optionally pass a hash of options to customize the queue settings such as path
, mmap_size
, and sync
.
queue = Litequeue.new
To add an item to a queue, use the push
method. You can specify the item's delay time in seconds (default is 0) and a queue name (default is "default"). This method returns a unique job ID.
id = queue.push("somevalue", 2) # The value will be ready to pop in 2 seconds
To add an item back into the queue possibly with a new value or delay, use the repush
method with the job ID.
queue.repush(id, "newvalue", 3)
To remove and return the next item from a queue, use the pop
method. You can specify a queue name and limit the number of items to pop (default is 1).
item = queue.pop # By default, pops from the "default" queue
If you have multiple queues, specify the queue name to pop items from a specific queue.
item = queue.pop("myQueue")
To delete an item from a queue before it is popped, use the delete
method with the item's job ID.
queue.delete(id)
To delete all items from all queues or from a specific queue, use the clear
method. If no queue name is given, all entries in all queues are deleted.
queue.clear # Clears all queues
queue.clear("myQueue") # Clears items from "myQueue" only
To get a count of items in all queues or in a specific queue, use the count
method.
total = queue.count # Count items in all queues
specific_total = queue.count("myQueue") # Count items in "myQueue"
To interact with a specific queue (e.g., adding, popping, deleting items), simply specify the queue name as an argument in the push
, pop
, delete
, or count
methods.
# Adding to a specific queue
queue.push("value", 0, "specificQueue")
# Popping from a specific queue
item = queue.pop("specificQueue")
# Counting items in a specific queue
count = queue.count("specificQueue")