qatar

package module
v0.0.0-...-cf1f752 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2020 License: MIT Imports: 2 Imported by: 0

README

qatar

qatar is a simple queuing system backed by an on-disk key-value store using pebble. You can enqueue or dequeue a payload of type []byte

Usage

To create a queue, you just need to provide a directory.

q, err := qatar.NewQ("/tmp/dir")

You can Peek without dequeueing by doing the following

// to peek a single item
item, err := q.Peek()

// To peek atmost 10 items
items, err := q.PeekMulti(10)

You can dequeue items like so

item, err := q.Dequeue()

Items consist of an Id and a payload of Data

You can directly delete an item from the queue (in any position), by doing the following

err := q.Delete(item.Id)

Documentation

Overview

`qatar` is a simple queuing system backed by an on-disk key-value store using `pebble`. You can enqueue or dequeue a payload of type `[]byte`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	Id   ksuid.KSUID
	Data []byte
}

Struct corresponding to an Item that is returned from the queue

type Q

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

Struct corresponding to a queue.

func CreateQ

func CreateQ(dirName string) (*Q, error)

Creates a queue in the specified directory. If this directory already exists, then we get an error. If opening an existing queue, use `OpenQ` instead.

func NewQ

func NewQ(dirName string) (*Q, error)

Sets up a new queue, with the `pebble` store in directory `dirName`. Do remember to call `Close()` on the instance of `*Q` that is returned.

func OpenQ

func OpenQ(dirName string) (*Q, error)

Opens an existing queue in the specified directory. If this directory does not exist, then an error is returned. To create a queue, use the `CreateQ` method.

func (*Q) Close

func (q *Q) Close()

Cleans up by closing the underlying db

func (*Q) Count

func (q *Q) Count() (int, error)

Returns the number of items in the queue. Note that this consists of scanning the entire queue, and can be very expensive. There is no caching provided.

func (*Q) Delete

func (q *Q) Delete(id ksuid.KSUID) error

Deletes the specified `id` from the queue. This can be in any position, and need not be at the tail of the queue.

func (*Q) Dequeue

func (q *Q) Dequeue() (*Item, error)

`Dequeue` operates as a `Peek()` and then a `Delete()` of the Item from the queue

func (*Q) DequeueAfter

func (q *Q) DequeueAfter(id ksuid.KSUID) (*Item, error)

Peeks and deletes the first item after the provided id.

func (*Q) Enqueue

func (q *Q) Enqueue(data []byte) (id ksuid.KSUID, err error)

Enqueues data and returns the id of the corresponding entry in the key value store. This id can be used to directly delete the entry.

func (*Q) EnqueueWithId

func (q *Q) EnqueueWithId(data []byte, id ksuid.KSUID) error

Enqueue items with a specified id

func (*Q) Peek

func (q *Q) Peek() (*Item, error)

`Peek()` returns the first item if any. It does not dequeue the item

func (*Q) PeekAfter

func (q *Q) PeekAfter(id ksuid.KSUID) (*Item, error)

func (*Q) PeekMulti

func (q *Q) PeekMulti(num int) ([]Item, error)

Peeks atmost `num` items from the queue. It does not dequeue these.

func (*Q) PeekMultiAfter

func (q *Q) PeekMultiAfter(num int, id ksuid.KSUID) ([]Item, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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