Skip to content

a reliable, lightweight, fast message queue for golang

License

Notifications You must be signed in to change notification settings

asheswook/redis-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

a reliable, lightweight, fast message queue for golang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages