You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

  1. # levelqueue
  2. Level queue is a simple queue golang library base on go-leveldb.
  3. [![Build Status](https://drone.gitea.com/api/badges/lunny/levelqueue/status.svg)](https://drone.gitea.com/lunny/levelqueue) [![](http://gocover.io/_badge/gitea.com/lunny/levelqueue)](http://gocover.io/gitea.com/lunny/levelqueue)
  4. [![](https://goreportcard.com/badge/gitea.com/lunny/levelqueue)](https://goreportcard.com/report/gitea.com/lunny/levelqueue)
  5. ## Installation
  6. ```
  7. go get gitea.com/lunny/levelqueue
  8. ```
  9. ## Usage
  10. ```Go
  11. queue, err := levelqueue.Open("./queue")
  12. err = queue.RPush([]byte("test"))
  13. // pop an element from left of the queue
  14. data, err = queue.LPop()
  15. // if handle success, element will be pop, otherwise it will be keep
  16. queue.LHandle(func(dt []byte) error{
  17. return nil
  18. })
  19. ```
  20. You can now create a Set from a leveldb:
  21. ```Go
  22. set, err := levelqueue.OpenSet("./set")
  23. added, err:= set.Add([]byte("member1"))
  24. has, err := set.Has([]byte("member1"))
  25. members, err := set.Members()
  26. removed, err := set.Remove([]byte("member1"))
  27. ```
  28. And you can create a UniqueQueue from a leveldb:
  29. ```Go
  30. queue, err := levelqueue.OpenUnique("./queue")
  31. err := queue.RPush([]byte("member1"))
  32. err = queue.LPush([]byte("member1"))
  33. // Will return ErrAlreadyInQueue
  34. // and so on.
  35. ```
  36. ## Creating Queues, UniqueQueues and Sets from already open DB
  37. If you have an already open DB you can create these from this using the
  38. `NewQueue`, `NewUniqueQueue` and `NewSet` functions.