ringer is a lightweight Go library providing lock-free data structures. It features an MPMC (Multi-Producer Multi-Consumer) RingBuffer and a thread-safe Rotator.
- Zero Locks: Built on atomic operations for maximum throughput.
- Cache-Optimized: Prevents false sharing with CPU cache line padding.
- Modern API: Rotator provide iterator with iter.Seq (Go 1.23+)
go get github.com/imatakatsu/ringerpackage main
import (
"fmt"
"github.com/imatakatsu/ringer"
)
func main() {
// Create a buffer from an existing slice
buf := ringer.BufferFromSlice([]string{"Alexey", "Georgy"})
// Pop an item
val, _ := buf.Pop()
fmt.Println("First user:", *val)
// Push it back
_ = buf.Push(val)
}First user: Alexey
package main
import (
"fmt"
"github.com/imatakatsu/ringer"
)
func main() {
r := ringer.NewRotator([]string{"node-1", "node-2", "node-3"})
// Infinite rotation using Ring() iterator (Go 1.23+)
count := 0
for node := range r.Ring() {
fmt.Println(node)
count++
if count == 4 { break }
}
}node-1
node-2
node-3
node-1