https://github.com/stellaraf/go-task-queue
A Redis-backed task queue with a simple API
https://github.com/stellaraf/go-task-queue
Last synced: 2 months ago
JSON representation
A Redis-backed task queue with a simple API
- Host: GitHub
- URL: https://github.com/stellaraf/go-task-queue
- Owner: stellaraf
- License: bsd-3-clause-clear
- Created: 2023-09-18T20:02:38.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-31T20:32:20.000Z (over 2 years ago)
- Last Synced: 2025-12-26T20:10:54.361Z (6 months ago)
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Usage
## Basic Task Queue
`BasicTaskQueue` is a simple task queue that stores tasks as strings.
```go
queue, err := taskqueue.NewBasic("queue-name")
queue.Add("example1", "example2")
value := queue.Pop()
// example1
value = queue.Pop()
// example2
```
## JSON Task Queue
`JSONTaskQueue` provides a very similar API to `BasicTaskQueue` and has the ability to store virtually any objet type as a task.
```go
type Data struct {
System string
Count int
}
type Task struct {
ID string `json:"id"`
Details []string `json:"details"`
Timestamp time.Time `json:"timestamp"`
Data *Data `json:"data"`
}
task := Task{
ID: "1234",
Details: []string{"some", "details"},
Timestamp: time.Now(),
Data: &Data{System: "aws", Count: 5},
}
queue, err := taskqueue.NewJSON("queue-name")
queue.Add(task)
var fromQueue *Task
queue.Pop(&fromQueue)
```
## Options
Both `BasicTaskQueue` and `JSONTaskQueue` support the same options:
```go
taskqueue.NewBasic(
"queue-name",
// Use a Redis connection string instead of WithHost/WithUsername/WithPassword.
taskqueue.WithURI("redis://redis-username:redispassword@your-redis-host.example.com:55032"),
// Set the Redis hostname. By default, this is localhost.
taskqueue.WithHost("your-redis-host.example.com"),
// Set the Redis username.
taskqueue.WithUsername("redis-username"),
// Set the Redis password.
taskqueue.WithPassword("redis-password"),
// Use your own context object. Useful if operating from within a web request.
taskqueue.WithContext(context.Background()),
// Set a Redis read/write timeout.
taskqueue.WithTimeout(time.Seconds*10),
// Add your own TLS configuration.
taskqueue.WithTLSConfig(&tls.Config{InsecureSkipVerify: true}),
// Don't re-add tasks to the queue that fail when unmarshaled.
taskqueue.WithNoRetry(),
)
```