hq

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 5 Imported by: 0

README

happy little queue

97% covered, 90LOC, 80_000RPS, integration test, auto-cleaning, lightweight

Go Reference Go Report Card OpenSSF Scorecard

When your Go code does not panic
When your infra does not fail
When your data is small
When your data is temporary
When all you need is a happy little queue

// once you have a redis connection
rdb := redis.NewClient(...)             // "github.com/go-redis/redis/v8"     

...

// you can boot a lightweight worker
worker := hq.ReceiveWorker{
    Redis:      rdb,
    Queue:      "my-queue",
    PoolIdle:   time.Minute,            // recommended!
    PoolActive: time.Millisecond * 50,  // recommended! 
    NumWorkers: 10,                     // recommended!
    Batch:      100,                    // recommended!
    Handler:    &handler,               // interface { Handle(message []byte) error }
}
go worker.Work()

...

// and send something
sender := hq.Sender{
    Redis:  rdb,
    Queue:  "my-queue",
    MaxLen: 10,
    TTL:    time.Hour * 4,
}
sender.Send([]byte("my-bytes"))

// in redis it is single list
// LLEN my-queue

It is as fast as Redis, so should be around 80_000RPS.

P.S. "happy" because optimistic

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReceiveWorker

type ReceiveWorker struct {
	Redis      *redis.Client
	Queue      string
	PoolIdle   time.Duration
	PoolActive time.Duration
	Handler    interface{ Handle(message []byte) error }
	NumWorkers uint
	Batch      uint
	// contains filtered or unexported fields
}

func (*ReceiveWorker) Stop

func (r *ReceiveWorker) Stop()

func (*ReceiveWorker) Work

func (r *ReceiveWorker) Work()

type Sender

type Sender struct {
	Redis  *redis.Client
	Queue  string
	MaxLen uint
	TTL    time.Duration
}

func (Sender) Send

func (s Sender) Send(message []byte) error

Jump to

Keyboard shortcuts

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