littleredqueue

package module
v0.0.0-...-e9740c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 2 Imported by: 0

README

go-little-red-queue Build Status Documentation

Go version of the little-red-queue php library: little-red-queue

It supports priority, at 3 levels: low, normal, high.

These use different queues, the get method'll choose a value from them.

Install

Via go get

$ go get github.com/gerifield/go-little-red-queue

Example

package main
import (
	littleredqueue "github.com/gerifield/go-little-red-queue"
	"github.com/gomodule/redigo/redis"
)

queue := littleredqueue.NewQueue[string](redis.Dial("tcp", "host:port"))

//Put an element into the queue with normal priority
l, _ := queue.PutNormal("key", "value")
fmt.Printf("QueueLength: %d", l)

//Put an element into the queue with high priority
l, err := queue.PutHigh("key", "value")
fmt.Printf("QueueLength: %d\n", l)

//Get a value with 5 seconds timeout, 0 means infite blocking
res, err := queue.Get("test2", 5)
if err != nil {
	panic(err)
}
if res == nil {
	fmt.Println("Timeout")
} else {
	fmt.Printf("Value: %s\n", res)
}

Testing

$ go test .

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Constants

View Source
const (
	PRIORITY_HIGH   = "high"
	PRIORITY_NORMAL = "normal"
	PRIORITY_LOW    = "low"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T any] struct {
	Redis  redis.Conn
	Prefix string
}

func NewQueue

func NewQueue[T any](conn redis.Conn) *Queue[T]

NewQueue create a new queue

func NewQueueWithPrefix

func NewQueueWithPrefix[T any](conn redis.Conn, prefix string) *Queue[T]

NewQueueWithPrefix create a queue with a specific prefix

func (*Queue[T]) Get

func (q *Queue[T]) Get(key string, timeout int64) (T, error)

Get an element form queue At timeout the result and the error will be nil

func (*Queue[T]) PutHigh

func (q *Queue[T]) PutHigh(key string, value T) (int64, error)

PutHigh put an element into the queue with high priority

func (*Queue[T]) PutLow

func (q *Queue[T]) PutLow(key string, value T) (int64, error)

PutLow put an element into the queue with low priority

func (*Queue[T]) PutNormal

func (q *Queue[T]) PutNormal(key string, value T) (int64, error)

PutNormal put an element into the queue with normal priority

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL