Skip to content

oliveagle/boltq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

boltq

boltq is a very simple boltdb based embedded queue

##usage

import (
	"fmt"
	"github.com/oliveagle/boltq"
)

func main() {
	// max_queue_size is 1
	q, err := boltq.NewBoltQ("test_q.queue", 1, boltq.ERROR_ON_FULL)
	defer q.Close()

	q.Enqueue([]byte("value"))
	
	// queue now is full, enqueue another item will raise an error
	err := q.Enqueue([]byte("value"))
	fmt.Println(err)

	// check if queue is full
	isFull := q.IsFull()
	fmt.Println(q.Size() >= q.GetMaxQueueSize())

	// dequeue
	value, _ := q.Dequeue()
	
	// dequeue an empty queue will raise an error
	_, err = q.Dequeue()
	

	// work like a stack
	q.Push([]byte("value"))
	value, _ := q.Pop()

	// can also pop from stack bottom
	value, _ := q.PopBottom()

	// pop many item with a filter func, the function will return 
	// once filter function returned the very first `false` and
	// all values with true returned by filter function will be deleted
	// from queue
	err := q.PopMany(func(v []byte) bool {
		i, _ := strconv.Atoi(fmt.Sprintf("%s", v))
		if i > 1 {
			return true
		}
		return false
	})

	// pop many also have a from-bottom version.
	err := q.PopManyBottom(func(v []byte) bool {
		i, _ := strconv.Atoi(fmt.Sprintf("%s", v))
		if i > 1 {
			return true
		}
		return false
	})
}

About

boltq is a very simple boltdb based embedded queue

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages