boltq

package module
v0.0.0-...-92e945c Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2015 License: Apache-2.0 Imports: 5 Imported by: 1

README

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
	})
}

Documentation

Index

Constants

View Source
const (
	ERROR_ON_FULL = iota // raise an error if the queue reached `max_queue_size`
	POP_ON_FULL          // popout oldest item if queue size above `max_queue_size`
)
View Source
const (
	BUCKET_STATS  = "~~stats~~"
	BUCKET_QUEUE  = "queue"
	KEY_TOTALITEM = "TotalItemCount"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BoltQ

type BoltQ struct {
	// contains filtered or unexported fields
}

func NewBoltQ

func NewBoltQ(filename string, max_queue_size int64, onfull int) (*BoltQ, error)

func (*BoltQ) Close

func (b *BoltQ) Close()

func (*BoltQ) Dequeue

func (b *BoltQ) Dequeue() (value []byte, err error)

func (*BoltQ) Enqueue

func (b *BoltQ) Enqueue(value []byte) (err error)

func (*BoltQ) GetMaxQueueSize

func (b *BoltQ) GetMaxQueueSize() int64

func (*BoltQ) IsFull

func (b *BoltQ) IsFull() bool

func (*BoltQ) Pop

func (b *BoltQ) Pop() (value []byte, err error)

func (*BoltQ) PopBottom

func (b *BoltQ) PopBottom() (value []byte, err error)

func (*BoltQ) PopMany

func (b *BoltQ) PopMany(fn func([]byte) bool) error

func (*BoltQ) PopManyBottom

func (b *BoltQ) PopManyBottom(fn func([]byte) bool) error

func (*BoltQ) Push

func (b *BoltQ) Push(value []byte) (err error)

func (*BoltQ) SetMaxQueueSize

func (b *BoltQ) SetMaxQueueSize(size int64)

func (*BoltQ) Size

func (b *BoltQ) Size() int64

Jump to

Keyboard shortcuts

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