Documentation
¶
Overview ¶
Package pogreb implements an embedded key-value store for read-heavy workloads.
Example ¶
package main
import (
"log"
"github.com/akrylysov/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"), []byte("testValue")); err != nil {
log.Fatal(err)
}
// Retrieve the inserted value.
val, err := db.Get([]byte("testKey"))
if err != nil {
log.Fatal(err)
}
log.Printf("%s", val)
// Iterate over items.
it := db.Items()
for {
key, val, err := it.Next()
if err == pogreb.ErrIterationDone {
break
}
if err != nil {
log.Fatal(err)
}
log.Printf("%s %s", key, val)
}
}
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) Delete(key []byte) error
- func (db *DB) FileSize() (int64, error)
- func (db *DB) Get(key []byte) ([]byte, error)
- func (db *DB) Has(key []byte) (bool, error)
- func (db *DB) Items() *ItemIterator
- func (db *DB) Metrics() *Metrics
- func (db *DB) Put(key []byte, value []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 // MaxValueLength is the maximum size of a value in bytes. MaxValueLength = 512 << 20 // 512 MiB // 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 ¶ added in v0.9.0
CompactionResult holds the compaction result.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents the key-value 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 ¶ added in v0.9.0
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.
func (*DB) Get ¶
Get returns the value for the given key stored in the DB or nil if the key doesn't exist.
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.
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.
