a reliable, lightweight message queue for golang
- Queue Interaction: Enables push and pop interactions with the message queue.
- Atomic: Handles push and pop operations atomically, providing safety against race conditions.
- Persistence: Ensures no message loss, even in the event of an unexpected program termination.
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()
}