Skip to content

a simple queue system supported by array and redis client

License

Notifications You must be signed in to change notification settings

RodolfoLemes/go-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛢️ Go Queue

Simple queue system supported by default array or slices and redis. Currently used to study about queue and golang. Feel free to comment, criticize or help.

Installation

go get -u github.com/RodolfoLemes/go-queue

Usage

To create a new queue or getting an existing one:

q := New[[]byte]("redis", "queueName", Options{RedisClient: rdb})

the T type dictated the element type inside the queue. The first argument is the driver, it can be redis or array, default is array. The second one is the name of the queue, the third and final one is the Options, required if you are using the redis driver.

To create a consumer, to consume the elements inside the queue, you can use:

c := NewConsumer(q)
defer c.Close()
for item := range c.Consume() {
	var data response
	json.Unmarshal(item, &data)
	log.Printf("consumer 2 got %v \n", data)
}

To create a producer, to append elements inside the queue, you can use:

p := NewProducer(q)
defer p.Close()

r := response{
	Data:  "b",
	IsTop: true,
	Massa: count,
}
data, _ := json.Marshal(r)

p.Produce() <- data

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

About

a simple queue system supported by array and redis client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages