0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-15 02:23:59 +01:00
gitea/vendor/gitea.com/lunny/levelqueue
guillep2k 64029e1468
Update lunny/levelqueue to 0.3.0 (#11285)
Co-authored-by: Guillermo Prandi <guillep2k@users.noreply.github.com>
2020-05-04 07:51:09 +01:00
..
.drone.yml upgrade levelqueue to 0.1.0 (#9192) 2019-11-28 23:37:33 +08:00
.gitignore Add Unique Queue infrastructure and move TestPullRequests to this (#9856) 2020-02-02 23:19:58 +00:00
error.go Add Unique Queue infrastructure and move TestPullRequests to this (#9856) 2020-02-02 23:19:58 +00:00
go.mod Update lunny/levelqueue to 0.3.0 (#11285) 2020-05-04 07:51:09 +01:00
go.sum Update lunny/levelqueue to 0.3.0 (#11285) 2020-05-04 07:51:09 +01:00
LICENSE upgrade levelqueue to 0.1.0 (#9192) 2019-11-28 23:37:33 +08:00
queue.go Update lunny/levelqueue to 0.3.0 (#11285) 2020-05-04 07:51:09 +01:00
README.md Add Unique Queue infrastructure and move TestPullRequests to this (#9856) 2020-02-02 23:19:58 +00:00
set.go Update lunny/levelqueue to 0.3.0 (#11285) 2020-05-04 07:51:09 +01:00
uniquequeue.go Update lunny/levelqueue to 0.3.0 (#11285) 2020-05-04 07:51:09 +01: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.