https://github.com/4x99/diskqueue
Disk-based FIFO queue
https://github.com/4x99/diskqueue
Last synced: 4 months ago
JSON representation
Disk-based FIFO queue
- Host: GitHub
- URL: https://github.com/4x99/diskqueue
- Owner: 4x99
- Created: 2022-02-17T01:48:36.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-08-10T03:16:14.000Z (over 2 years ago)
- Last Synced: 2025-02-09T11:31:04.031Z (11 months ago)
- Language: Go
- Size: 25.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DiskQueue
Disk-based FIFO queue
---
## Features
- FIFO
- High performance
---
## Getting Started
```
go get -u github.com/4x99/diskqueue
```
```
package main
import (
"fmt"
"github.com/4x99/diskqueue"
"log"
"time"
)
func main() {
var err error
var queue *diskqueue.Diskqueue
// config
diskqueue.Config.Path = "/tmp/diskqueue"
diskqueue.Config.BatchSize = 1
// start
if queue, err = diskqueue.Start(); err != nil {
log.Fatalln(err)
}
// write
go func() {
for {
time.Sleep(time.Second)
data := []byte(time.Now().Format("2006-01-02 15:04:05"))
if err := queue.Write(data); err != nil {
fmt.Println(err)
}
}
}()
// read
go func() {
for {
time.Sleep(time.Second)
if index, offset, data, err := queue.Read(); err == nil {
fmt.Println(index, offset, string(data))
queue.Commit(index, offset) // commit
}
}
}()
select {}
}
```
---
## Default Config
```
Config = &config{
Path: "data",
FilePerm: 0600,
BatchSize: 100,
BatchTime: time.Second,
SegmentSize: 50 * 1024 * 1024,
SegmentLimit: 2048,
WriteTimeout 300,
CheckpointFile: ".checkpoint",
MinRequiredSpace: 1024 * 1024 * 1024,
}
```