Go to file
Lunny Xiao 0a96ab90fd
checks / check and test (push) Failing after 1m2s Details
Use actions instead of drone
2023-04-21 11:39:32 +08:00
.gitea/workflows Use actions instead of drone 2023-04-21 11:39:32 +08:00
.gitignore Add Set and UniqueQueue implementations (#1) 2020-01-18 05:41:15 +00:00
LICENSE init project 2019-02-17 14:34:03 +08:00
README.md Use actions instead of drone 2023-04-21 11:39:32 +08:00
error.go Add Set and UniqueQueue implementations (#1) 2020-01-18 05:41:15 +00:00
go.mod Use pebble instead of leveldb 2022-03-05 20:43:26 +08:00
go.sum Use pebble instead of leveldb 2022-03-05 20:43:26 +08:00
queue.go Use pebble instead of leveldb 2022-03-05 20:43:26 +08:00
queue_test.go fix bug 2019-11-28 16:44:03 +08:00
set.go Use pebble instead of leveldb 2022-03-05 20:43:26 +08:00
set_test.go Add Set and UniqueQueue implementations (#1) 2020-01-18 05:41:15 +00:00
uniquequeue.go Use pebble instead of leveldb 2022-03-05 20:43:26 +08:00
uniquequeue_test.go Add Set and UniqueQueue implementations (#1) 2020-01-18 05:41:15 +00:00

README.md

pebblequeue

Pebble queue is a simple queue golang library base on pebbledb.

Installation

go get gitea.com/lunny/pebblequeue

Usage

queue, err := pebblequeue.Open("./queue")

err = queue.RPush([]byte("test"))

// pop an element from left of the queue
data, err = queue.LPop()

// if handle success, element will be pop, otherwise it will be keep
queue.LHandle(func(dt []byte) error{
    return nil
})

You can now create a Set from a pebbledb:

set, err := pebblequeue.OpenSet("./set")

added, err:= set.Add([]byte("member1"))

has, err := set.Has([]byte("member1"))

members, err := set.Members()

removed, err := set.Remove([]byte("member1"))

And you can create a UniqueQueue from a pebbledb:

queue, err := pebblequeue.OpenUnique("./queue")

err := queue.RPush([]byte("member1"))

err = queue.LPush([]byte("member1"))
// Will return ErrAlreadyInQueue

// and so on.

Creating Queues, UniqueQueues and Sets from already open DB

If you have an already open DB you can create these from this using the NewQueue, NewUniqueQueue and NewSet functions.