Documentation
¶
Overview ¶
Package pogreb implements an embedded key-value store for read-heavy workloads.
Example ¶
package main
import (
"log"
"github.com/domaincrawler/pogreb"
)
func main() {
db, err := pogreb.Open("pogreb.test", nil)
if err != nil {
log.Fatal(err)
return
}
defer db.Close()
// Insert a new key-value pair.
if err := db.Put([]byte("testKey")); err != nil {
log.Fatal(err)
}
// Retrieve the inserted value.
val, err := db.Has([]byte("testKey"))
if err != nil {
log.Fatal(err)
}
log.Println(val)
// Iterate over items.
it := db.Items()
for {
key, err := it.Next()
if err == pogreb.ErrIterationDone {
break
}
if err != nil {
log.Fatal(err)
}
log.Printf("%s", key)
}
}
Index ¶
- Constants
- Variables
- func SetLogger(l *log.Logger)
- type CompactionResult
- type DB
- func (db *DB) Close() error
- func (db *DB) Compact() (CompactionResult, error)
- func (db *DB) Count() uint32
- func (db *DB) FileSize() (int64, error)
- func (db *DB) Has(key []byte) (bool, error)
- func (db *DB) HasOrPut(key []byte) (bool, error)
- func (db *DB) Items() *ItemIterator
- func (db *DB) Metrics() *Metrics
- func (db *DB) Put(key []byte) error
- func (db *DB) Sync() error
- type ItemIterator
- type Metrics
- type Options
Examples ¶
Constants ¶
const ( // MaxKeyLength is the maximum size of a key in bytes. MaxKeyLength = math.MaxUint16 // MaxKeys is the maximum numbers of keys in the DB. MaxKeys = math.MaxUint32 )
Variables ¶
var ErrIterationDone = errors.New("no more items in iterator")
ErrIterationDone is returned by ItemIterator.Next calls when there are no more items to return.
Functions ¶
Types ¶
type CompactionResult ¶
CompactionResult holds the compaction result.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents the key-only storage. All DB methods are safe for concurrent use by multiple goroutines.
func Open ¶
Open opens or creates a new DB. The DB must be closed after use, by calling Close method.
func (*DB) Compact ¶
func (db *DB) Compact() (CompactionResult, error)
Compact compacts the DB. Deleted and overwritten items are discarded. Returns an error if compaction is already in progress.
type ItemIterator ¶
type ItemIterator struct {
// contains filtered or unexported fields
}
ItemIterator is an iterator over DB key-value pairs. It iterates the items in an unspecified order.
func (*ItemIterator) Next ¶
func (it *ItemIterator) Next() ([]byte, error)
Next returns the next key-value pair if available, otherwise it returns ErrIterationDone error.
type Options ¶
type Options struct {
// BackgroundSyncInterval sets the amount of time between background Sync() calls.
//
// Setting the value to 0 disables the automatic background synchronization.
// Setting the value to -1 makes the DB call Sync() after every write operation.
BackgroundSyncInterval time.Duration
// BackgroundCompactionInterval sets the amount of time between background Compact() calls.
//
// Setting the value to 0 disables the automatic background compaction.
BackgroundCompactionInterval time.Duration
// FileSystem sets the file system implementation.
//
// Default: fs.OSMMap.
FileSystem fs.FileSystem
// contains filtered or unexported fields
}
Options holds the optional DB parameters.