1 unstable release

0.1.7 Jul 24, 2024
0.1.6 Jul 24, 2024
0.1.5 Mar 28, 2024

#791 in Database interfaces

Download history 233/week @ 2024-07-23 8/week @ 2024-07-30 15/week @ 2024-09-10 4/week @ 2024-09-17 17/week @ 2024-09-24 12/week @ 2024-10-01

316 downloads per month

MIT license

33KB
781 lines

RedisQueueRS

A simple Redis queue implementation in Rust.

This project ofers two implementations: RedisQueue and AsyncRedisQueue. Both of them are based on the same RedisQueue struct and are thread safe due to the use of a Redis key based lock, but the AsyncRedisQueue uses async/await to handle the Redis connection.

This project is considered a work in progress and is not yet ready for production use.

Advantages of a Redis Queue

  • Decoupling: The producer and the consumer are decoupled. The producer can produce messages without worrying about the consumer.
  • Scalability: The producer and the consumer can be scaled independently.
  • Reliability: The queue can be used to store messages in case of failure.
  • Asynchronous Communication: The producer and the consumer can be asynchronous.
  • Load Balancing: The queue can be used to balance the load between multiple consumers.

Installation

Add the following to your Cargo.toml:

[dependencies]
redis-queue-rs = "*"

Usage

RedisQueue - Synchronous Implementation

use redis_queue_rs::redis_queue::RedisQueue;
use redis::Client;

fn main() {
    let redis_client = Client::open("redis://127.0.0.1:6379").unwrap();
    
    let mut redis_queue = RedisQueue::new(
        "name_of_queue".to_string(),
        redis_client,
    );
    
    let item = "test".to_string();
    
    redis_queue.push(item.clone());
    let result = redis_queue.pop().unwrap();
}

AsyncRedisQueue - Asynchronous Implementation

use redis_queue_rs::async_redis_queue::AsyncRedisQueue;
use redis::Client;

#[tokio::main]
async fn main() {
    let redis_client = Client::open("redis://127.0.0.1:6379").unwrap();
    
    let mut redis_queue = AsyncRedisQueue::new(
        "name_of_queue".to_string(),
        redis_client,
    ).await;
    
    let item = "test".to_string();

    redis_queue.push(item.clone()).await;
    let result = redis_queue.pop().await.unwrap();
}

License

This project is licensed under the MIT License, feel free to use it in your projects :)

Dependencies

~12–23MB
~346K SLoC