Documentation ¶
Index ¶
- Variables
- func FastRand() uint32
- type DB
- func (db *DB) Begin(readonly bool) (*Txn, error)
- func (db *DB) Close() error
- func (db *DB) Del(key Key) error
- func (db *DB) Expire(key Key, ttl time.Duration) error
- func (db *DB) Get(key Key) (Value, error)
- func (db *DB) Merge(transfer bool) error
- func (db *DB) Purge() error
- func (db *DB) Put(key Key, value Value, ttl time.Duration) error
- func (db *DB) Range(option RangeOptions, handler RangeHandler) error
- func (db *DB) Sync() error
- func (db *DB) TTL(key Key) (time.Duration, error)
- type Key
- type Option
- type Options
- type RangeHandler
- type RangeOptions
- type Txn
- func (txn *Txn) Commit() error
- func (txn *Txn) Del(key Key) error
- func (txn *Txn) Expire(key Key, ttl time.Duration) error
- func (txn *Txn) Get(key Key) (Value, error)
- func (txn *Txn) Put(key Key, value Value, ttl time.Duration) error
- func (txn *Txn) Range(opt RangeOptions, handler RangeHandler) error
- func (txn *Txn) RollBack() error
- func (txn *Txn) TTL(key Key) (time.Duration, error)
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( ErrKeyNotFound = errors.New("key not found") ErrNilKey = entry.ErrNilKey ErrDBClosed = errors.New("db is already closed") ErrDBMerging = errors.New("db is merging data") ErrDirAlreadyUsed = errors.New("dir already used by another process") )
var ( ErrTxnClosed = errors.New("transaction is closed") ErrTxnReadonly = errors.New("transaction is read-only") ErrTxnConflict = errors.New("transaction is conflict") )
var DefaultOptions = Options{ MaxSize: defaultMaxFileSize, BlockCache: defaultMaxFileSize / file.MB, Fsync: false, FsyncThreshold: blockSize * (defaultMaxFileSize / file.MB), Compare: index.DefaultCompare, }
var (
ErrMergedNotFinished = errors.New("merged not finished")
)
Functions ¶
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents a db instance, which stores wal file in a specific data directory
func (*DB) Del ¶
Del remove the key-value pair match the give key from db. it will return nil if key not exist
func (*DB) Merge ¶
Merge clean the redundant data entry in db, shrinking the db size if transfer is false, it will only record of merged data, will not replace them to data dir
func (*DB) Put ¶
Put puts a key-value pair into db, overwrite value if key already exists. nil key is invalid, but nil value is allowed. if tll == 0, key will be persisted, or ttl < 0, key will apply the previous ttl.
func (*DB) Range ¶
func (db *DB) Range(option RangeOptions, handler RangeHandler) error
Range iterates over all the keys that match the given RangeOption and call handler for each key-value
type Option ¶
type Option func(option *Options)
Option applying changes to the given option
func WithBlockCache ¶
func WithClosedGc ¶
func WithCompare ¶
func WithFsyncThreshold ¶
func WithMaxSize ¶
type Options ¶
type Options struct { // data dir that stores data files Dir string // max bytes size of the single data file can hold MaxSize int64 // wal block cache size BlockCache uint32 // call sync per write Fsync bool // call sync when reach the threshold FsyncThreshold int64 // decide how to sort keys Compare index.Compare // manually gc after closed db ClosedGc bool // contains filtered or unexported fields }
Options represent db configuration
type RangeHandler ¶
RangeHandler iterate over key-value in db
type RangeOptions ¶
type RangeOptions = index.RangeOption
type Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
Txn represents a transaction
func (*Txn) Range ¶
func (txn *Txn) Range(opt RangeOptions, handler RangeHandler) error