https://github.com/mvalitov/elixir-redis-unique-queue
A unique FIFO queue with atomic operations built on top of Redis
https://github.com/mvalitov/elixir-redis-unique-queue
elixir queue redis
Last synced: 8 months ago
JSON representation
A unique FIFO queue with atomic operations built on top of Redis
- Host: GitHub
- URL: https://github.com/mvalitov/elixir-redis-unique-queue
- Owner: mvalitov
- License: mit
- Created: 2017-05-08T16:10:42.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-09-08T20:42:09.000Z (almost 8 years ago)
- Last Synced: 2025-01-17T14:07:40.581Z (over 1 year ago)
- Topics: elixir, queue, redis
- Language: Elixir
- Homepage:
- Size: 12.7 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# RedisUniqueQueue
Is the elixir-implementation of ruby-gem [ruby-redis-unique-queue](https://github.com/MishaConway/ruby-redis-unique-queue)
## Installation
Add `redis_unique_queue` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:redis_unique_queue, "~> 0.1.5"}]
end
```
Documentation [https://hexdocs.pm/redis_unique_queue](https://hexdocs.pm/redis_unique_queue).
## Usage
Queue creation:
* with options(redis host and port)
{:ok, queue} = RedisUniqueQueue.create("test_queue", %{host: "0.0.0.0", port: 6379})
* with Redix connection
{:ok, conn} = Redix.start_link(host: "0.0.0.0", port: 6379)
{:ok, queue} = RedisUniqueQueue.create("test_queue", conn)
Push data to the queue
RedisUniqueQueue.push(queue, "test")
Push multiple items onto the queue
RedisUniqueQueue.push_multi(queue, ["test2", "test3"])
Pop data from the queue
RedisUniqueQueue.pop(queue)
Atomically pop multiple items from the queue
RedisUniqueQueue.pop_multi(queue, 2)
Pop all items in the queue
RedisUniqueQueue.pop_all(queue)
Get the size of the queue
RedisUniqueQueue.size(queue)
Read the first item in the queue
RedisUniqueQueue.front(queue)
Read the last item in the queue
RedisUniqueQueue.back(queue)
See if an item exists in the queue
RedisUniqueQueue.include?(queue, "test")
Remove an arbitrary item from the queue
RedisUniqueQueue.remove(queue, "test2")
Remove an arbitrary item from the queue by index
RedisUniqueQueue.remove_item_by_index(queue, 2)
Get all items in the queue
RedisUniqueQueue.all(queue)
Peek into arbitrary ranges in the queue
RedisUniqueQueue.peek(queue)
The queue can be cleared of all items
RedisUniqueQueue.clear(queue)
Optionally, the queue can also be set to expire (in seconds).
RedisUniqueQueue.expire(queue, 60)