Documentation ¶
Overview ¶
Package keydb came from buntdb that implements a low-level in-memory key/value store in pure Go. It persists to disk, is ACID compliant, and uses locking for multiple readers and a single writer. Bunt is ideal for projects that need a dependable database, and favor speed over data size.
Package keydb came from buntdb that implements a low-level in-memory key/value store in pure Go. It persists to disk, is ACID compliant, and uses locking for multiple readers and a single writer. Bunt is ideal for projects that need a dependable database, and favor speed over data size.
Package keydb came from buntdb that implements a low-level in-memory key/value store in pure Go. It persists to disk, is ACID compliant, and uses locking for multiple readers and a single writer. Bunt is ideal for projects that need a dependable database, and favor speed over data size.
Index ¶
- Constants
- Variables
- type Config
- type DB
- type SyncPolicy
- type Tx
- func (tx *Tx) Ascend(iterator func(key []byte, value interface{}) bool) error
- func (tx *Tx) AscendEqual(pivot []byte, iterator func(key []byte, value interface{}) bool) error
- func (tx *Tx) AscendGreaterOrEqual(pivot []byte, iterator func(key []byte, value interface{}) bool) error
- func (tx *Tx) AscendLessThan(pivot []byte, iterator func(key []byte, value interface{}) bool) error
- func (tx *Tx) AscendRange(greaterOrEqual, lessThan []byte, ...) error
- func (tx *Tx) Commit() error
- func (tx *Tx) Delete(key []byte) error
- func (tx *Tx) DeleteAll() error
- func (tx *Tx) Descend(iterator func(key []byte, value interface{}) bool) error
- func (tx *Tx) DescendEqual(pivot []byte, iterator func(key []byte, value interface{}) bool) error
- func (tx *Tx) DescendGreaterThan(pivot []byte, iterator func(key []byte, value interface{}) bool) error
- func (tx *Tx) DescendLessOrEqual(pivot []byte, iterator func(key []byte, value interface{}) bool) error
- func (tx *Tx) DescendRange(lessOrEqual, greaterThan []byte, ...) error
- func (tx *Tx) Get(key []byte) (val interface{}, err error)
- func (tx *Tx) Iterate(prefix []byte, fn func(key []byte, value interface{}) error) error
- func (tx *Tx) Len() (int, error)
- func (tx *Tx) Rollback() error
- func (tx *Tx) Set(key []byte, value interface{}, data []byte) error
- type Unmarshaler
Constants ¶
const ( // Never is used to disable syncing data to disk. // The faster and less safe method. Never SyncPolicy = 0 // EverySecond is used to sync data to disk every second. // It's pretty fast and you can lose 1 second of data if there // is a disaster. // This is the recommended setting. EverySecond = 1 // Always is used to sync data after every write to disk. // Slow. Very safe. Always = 2 )
consts
Variables ¶
var ( // ErrTxNotWritable is returned when performing a write operation on a // read-only transaction. ErrTxNotWritable = errors.New("tx not writable") // ErrTxClosed is returned when committing or rolling back a transaction // that has already been committed or rolled back. ErrTxClosed = errors.New("tx closed") // ErrNotFound is returned when an item or index is not in the database. ErrNotFound = errors.New("not found") // ErrInvalidDatabase is returned when the database file is an invalid format. ErrInvalidDatabase = errors.New("invalid database") // ErrDatabaseClosed is returned when the database is closed. ErrDatabaseClosed = errors.New("database closed") // ErrInvalidOperation is returned when an operation cannot be completed. ErrInvalidOperation = errors.New("invalid operation") // ErrInvalidSyncPolicy is returned for an invalid SyncPolicy value. ErrInvalidSyncPolicy = errors.New("invalid sync policy") // ErrShrinkInProcess is returned when a shrink operation is in-process. ErrShrinkInProcess = errors.New("shrink is in-process") // ErrTxIterating is returned when Set or Delete are called while iterating. ErrTxIterating = errors.New("tx is iterating") ErrNotExistUnmarshaler = errors.New("not exist unmarshaler") )
errors
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // SyncPolicy adjusts how often the data is synced to disk. // This value can be Never, EverySecond, or Always. // The default is EverySecond. SyncPolicy SyncPolicy // AutoShrinkPercentage is used by the background process to trigger // a shrink of the aof file when the size of the file is larger than the // percentage of the result of the previous shrunk file. // For example, if this value is 100, and the last shrink process // resulted in a 100mb file, then the new aof file must be 200mb before // a shrink is triggered. AutoShrinkPercentage int // AutoShrinkMinSize defines the minimum size of the aof file before // an automatic shrink can occur. AutoShrinkMinSize int // AutoShrinkDisabled turns off automatic background shrinking AutoShrinkDisabled bool }
Config represents database configuration options. These options are used to change various behaviors of the database.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents a collection of key-value pairs that persist on disk. Transactions are used for all forms of data access to the DB.
func Open ¶
func Open(path string, fn Unmarshaler) (*DB, error)
Open opens a database at the provided path. If the file does not exist then it will be created automatically.
func (*DB) Begin ¶
Begin opens a new transaction. Multiple read-only transactions can be opened at the same time but there can only be one read/write transaction at a time. Attempting to open a read/write transactions while another one is in progress will result in blocking until the current read/write transaction is completed.
All transactions must be closed by calling Commit() or Rollback() when done.
func (*DB) Close ¶
Close releases all database resources. All transactions must be closed before closing the database.
func (*DB) ReadConfig ¶
ReadConfig returns the database configuration.
func (*DB) Shrink ¶
Shrink will make the database file smaller by removing redundant log entries. This operation does not block the database.
func (*DB) Update ¶
Update executes a function within a managed read/write transaction. The transaction has been committed when no error is returned. In the event that an error is returned, the transaction will be rolled back. When a non-nil error is returned from the function, the transaction will be rolled back and the that error will be return to the caller of Update().
Executing a manual commit or rollback from inside the function will result in a panic.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx represents a transaction on the database. This transaction can either be read-only or read/write. Read-only transactions can be used for retrieving values for keys and iterating through keys and values. Read/write transactions can set and delete keys.
All transactions must be committed or rolled-back when done.
func (*Tx) Ascend ¶
Ascend calls the iterator for every item in the database within the range [first, last], until iterator returns false. The results will be ordered by the item key.
func (*Tx) AscendEqual ¶
AscendEqual calls the iterator for every item in the database that equals pivot, until iterator returns false.
func (*Tx) AscendGreaterOrEqual ¶
func (tx *Tx) AscendGreaterOrEqual(pivot []byte, iterator func(key []byte, value interface{}) bool) error
AscendGreaterOrEqual calls the iterator for every item in the database within the range [pivot, last], until iterator returns false. The results will be ordered by the item key.
func (*Tx) AscendLessThan ¶
AscendLessThan calls the iterator for every item in the database within the range [first, pivot), until iterator returns false. The results will be ordered by the item key.
func (*Tx) AscendRange ¶
func (tx *Tx) AscendRange(greaterOrEqual, lessThan []byte, iterator func(key []byte, value interface{}) bool) error
AscendRange calls the iterator for every item in the database within the range [greaterOrEqual, lessThan), until iterator returns false. The results will be ordered by the item key.
func (*Tx) Commit ¶
Commit writes all changes to disk. An error is returned when a write error occurs, or when a Commit() is called from a read-only transaction.
func (*Tx) Delete ¶
Delete removes an item from the database based on the item's key. If the item does not exist then ErrNotFound is returned.
Only a writable transaction can be used for this operation. This operation is not allowed during iterations such as Ascend* & Descend*.
func (*Tx) Descend ¶
Descend calls the iterator for every item in the database within the range [last, first], until iterator returns false. The results will be ordered by the item key.
func (*Tx) DescendEqual ¶
DescendEqual calls the iterator for every item in the database that equals pivot, until iterator returns false.
func (*Tx) DescendGreaterThan ¶
func (tx *Tx) DescendGreaterThan(pivot []byte, iterator func(key []byte, value interface{}) bool) error
DescendGreaterThan calls the iterator for every item in the database within the range [last, pivot), until iterator returns false. The results will be ordered by the item key.
func (*Tx) DescendLessOrEqual ¶
func (tx *Tx) DescendLessOrEqual(pivot []byte, iterator func(key []byte, value interface{}) bool) error
DescendLessOrEqual calls the iterator for every item in the database within the range [pivot, first], until iterator returns false. The results will be ordered by the item key.
func (*Tx) DescendRange ¶
func (tx *Tx) DescendRange(lessOrEqual, greaterThan []byte, iterator func(key []byte, value interface{}) bool) error
DescendRange calls the iterator for every item in the database within the range [lessOrEqual, greaterThan), until iterator returns false. The results will be ordered by the item key.
func (*Tx) Get ¶
Get returns a value for a key. If the item does not exist then ErrNotFound is returned
func (*Tx) Rollback ¶
Rollback closes the transaction and reverts all mutable operations that were performed on the transaction such as Set() and Delete().
Read-only transactions can only be rolled back, not committed.
func (*Tx) Set ¶
Set inserts or replaces an item in the database based on the key. The opt params may be used for additional functionality such as forcing the item to be evicted at a specified time. When the return value for err is nil the operation succeeded. When the return value of replaced is true, then the operaton replaced an existing item whose value will be returned through the previousValue variable. The results of this operation will not be available to other transactions until the current transaction has successfully committed.
Only a writable transaction can be used with this operation. This operation is not allowed during iterations such as Ascend* & Descend*.
type Unmarshaler ¶
Unmarshaler needs to unmarshal structures