A golang queue library based on go-leveldb
Go to file
Andrew Thornton 47d1e224cd
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
lowLock must be locked before highLock in the queue (#5)
Unfortunately the locking order in the queue.Close() function is
incorrect as the queue.Len() function locks the lowLock before the
highLock.  We therefore must lock the lowLock before the highLock.

Signed-off-by: Andrew Thornton <art27@cantab.net>

Reviewed-on: #5
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
2021-08-14 21:14:25 +08:00
.circleci init project 2019-02-17 14:34:03 +08:00
.drone.yml upgrade drone format 2019-11-28 16:49:28 +08:00
.gitignore Add Set and UniqueQueue implementations (#1) 2020-01-18 05:41:15 +00:00
error.go Add Set and UniqueQueue implementations (#1) 2020-01-18 05:41:15 +00:00
go.mod Update with go get -u (#3) 2020-05-04 03:01:34 +00:00
go.sum Update with go get -u (#3) 2020-05-04 03:01:34 +00:00
LICENSE init project 2019-02-17 14:34:03 +08:00
queue_test.go fix bug 2019-11-28 16:44:03 +08:00
queue.go lowLock must be locked before highLock in the queue (#5) 2021-08-14 21:14:25 +08:00
README.md Add Set and UniqueQueue implementations (#1) 2020-01-18 05:41:15 +00:00
set_test.go Add Set and UniqueQueue implementations (#1) 2020-01-18 05:41:15 +00:00
set.go Fix race relating to Close (#4) 2021-07-27 09:48:41 +08:00
uniquequeue_test.go Add Set and UniqueQueue implementations (#1) 2020-01-18 05:41:15 +00:00
uniquequeue.go Fix race relating to Close (#4) 2021-07-27 09:48:41 +08:00

levelqueue

Level queue is a simple queue golang library base on go-leveldb.

Build Status

Installation

go get gitea.com/lunny/levelqueue

Usage

queue, err := levelqueue.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 leveldb:

set, err := levelqueue.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 leveldb:

queue, err := levelqueue.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.