/go-little-red-queue

Go version of the little-red-queue php library

Primary LanguageGoMIT LicenseMIT

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.