Categorygithub.com/asheswook/redis-queue
modulepackage
0.0.0-20240504084743-b0a5b4a6c757
Repository: https://github.com/asheswook/redis-queue.git
Documentation: pkg.go.dev

# README

redis-queue

a reliable, lightweight message queue for golang

Feature

  1. Queue Interaction: Enables push and pop interactions with the message queue.
  2. Atomic: Handles push and pop operations atomically, providing safety against race conditions.
  3. Persistence: Ensures no message loss, even in the event of an unexpected program termination.

Usage

go get -u github.com/asheswook/redis-queue
package main

import (
  "github.com/redis/go-redis/v9"
  redisqueue "github.com/asheswook/redis-queue"
)

func main() {
  // Using go-redis client
  // You can also use normal client instead of cluster client
  client := redis.NewClusterClient( 
    &redis.ClusterOptions{
      Addrs: config.Addrs,
    },
  )

  queue := redisqueue.NewSafeQueue(
    &redisqueue.Config{
      Redis: client,
      Queue: struct {
        Name  string
        Retry int
      }{
        Name:  fmt.Sprintf("{%s}", "YOUR_QUEUE_NAME"),
        Retry: config.Retry,
      },
      Safe: struct {
        AckZSetName string
        TTL         int
      }{
        AckZSetName: fmt.Sprintf("{%s}:ack", "YOUR_ACK_ZSET_NAME"),
        TTL:         config.TTL,
      },
    },
  )

  err := queue.Push("testPayload")
  msg, err := queue.SafePop()
  if msg == nil && err == nil {
    // No message
  }

  if err != nil {
    // Error
  }

  // Signal the message has been processed successfully.
  _ = msg.Ack()
}

How it works

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

CommonMessage is a simple message.
CommonQueue is a simple queue.
No description provided by the author
SafeMessage is a message that can be acked.
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author