Documentation ¶
Index ¶
- Constants
- Variables
- func Apply(db *Database, driver string, loader func(interface{}) error) error
- func Factories() []string
- func Register(name string, f Factory)
- func UnregisterAll()
- type Config
- type Database
- type Driver
- type Factory
- type Feature
- type IsolationLevel
- type Nop
- func (n Nop) Begin() (Transaction, error)
- func (n Nop) Delete(key []byte) error
- func (n Nop) DeleteCounter(key []byte) error
- func (n Nop) Features() Feature
- func (n Nop) Get(key []byte) ([]byte, error)
- func (n Nop) GetCounter(key []byte) (int64, error)
- func (n Nop) IncreaseCounter(key []byte, incr int64) (int64, error)
- func (n Nop) IncreaseCounterWithTTL(key []byte, incr int64, ttlInSecond int64) (int64, error)
- func (n Nop) Insert(Key []byte, value []byte) (bool, error)
- func (n Nop) InsertWithTTL(Key []byte, value []byte, ttlInSecond int64) (bool, error)
- func (n Nop) IsolationLevel() IsolationLevel
- func (n Nop) Next(iter []byte, limit int) (kv []*herbdata.KeyValue, newiter []byte, err error)
- func (n Nop) Prev(iter []byte, limit int) (kv []*herbdata.KeyValue, newiter []byte, err error)
- func (n Nop) Set(key []byte, value []byte) error
- func (n Nop) SetCounter(key []byte, value int64) error
- func (n Nop) SetCounterWithTTL(key []byte, value int64, ttlInSecond int64) error
- func (n Nop) SetErrorHanlder(func(error))
- func (n Nop) SetWithExpired(key []byte, value []byte, expired int64) error
- func (n Nop) SetWithTTL(key []byte, value []byte, ttlInSecond int64) error
- func (n Nop) Start() error
- func (n Nop) Stop() error
- func (n Nop) Update(key []byte, value []byte) (bool, error)
- func (n Nop) UpdateWithTTL(key []byte, value []byte, ttlInSecond int64) (bool, error)
- type Transaction
Constants ¶
const ( //FeatureStore key-value database store(Set/Get/Delete) feature FeatureStore = Feature(1 << iota) //FeatureTTLStore key-value database ttl store(SetWithTTL/Get/Delete) feature FeatureTTLStore //FeatureExpiredStore key-value database expired store(SetWithExpired/Get/Delete) feature FeatureExpiredStore //FeatureCounter key-value database counter(SetCounter/IncreaseCounter/GetCounter/DeleteCounter) feature FeatureCounter //FeatureTTLCounter key-value database counter(SetCounterWithTTL/IncreaseCounterWithTTL/GetCounter/DeleteCounter) feature FeatureTTLCounter //FeatureNext key-value database next (Next) feature FeatureNext //FeaturePrev key-value database prev (Prev) feature FeaturePrev //FeatureInsert key-value database insert (Insert) feature FeatureInsert //FeatureTTLInsert key-value database ttl insert (InsertWithTTL) feature FeatureTTLInsert //FeatureUpdate key-value database update (Update) feature FeatureUpdate //FeatureTTLUpdate key-value database ttl update (UpdateWithTTL) feature FeatureTTLUpdate //FeatureTransaction key-value database transactio(Begin) feature FeatureTransaction //FeatureNonpersistent if data will be drop after application restart FeatureNonpersistent //FeatureUnstable if data may be droped if needed. FeatureUnstable //FeatureEmbedded if database is embedded. FeatureEmbedded )
const ( //IsolationLevelBatch isolation-level batch.Batch insert data,get data in transaction will return data in databse directly. IsolationLevelBatch = IsolationLevel(1 << iota) //IsolationLevelReadUncommitted isolation-level read uncommitted IsolationLevelReadUncommitted //IsolationLevelReadCommitted isolation-level read committed IsolationLevelReadCommitted //IsolationLevelRepeatableRead isolation-level repeatable read IsolationLevelRepeatableRead //IsolationLevelSerializable isolation-level serializable IsolationLevelSerializable )
const FeaturesSetEmpty = Feature(0)
FeaturesSetEmpty empty feature set
Variables ¶
var ErrFeatureNotSupported = errors.New("feature not supported")
ErrFeatureNotSupported error raised if given feature is not supported
var ErrFeatureSupported = errors.New("feature supported")
ErrFeatureSupported error raised if given feature is supported
var ErrUnsupportedNextLimit = errors.New("unsuported next limit")
ErrUnsupportedNextLimit error raised when next limit unsupported
var Passthrough = &passthrough{}
Passthrough key value database which do not store any data
var SuggestedCounterPrefix = []byte{1}
SuggestedCounterPrefix suggest key prefix for counter/ttlcounter feature
var SuggestedDataPrefix = []byte{0}
SuggestedDataPrefix suggest key prefix for store/ttlstore feature
Functions ¶
func Factories ¶
func Factories() []string
Factories returns a sorted list of the names of the registered factories.
Types ¶
type Database ¶
type Database struct {
Driver
}
Database key-value database struct
func (*Database) ShouldNotSupport ¶
ShouldNotSupport return ErrFeatureSupported if any given feature be supported by driver
func (*Database) ShouldSupport ¶
ShouldSupport return ErrFeatureNotSupported if any given feature not be supported by driver
type Driver ¶
type Driver interface { //Start start database Start() error //Stop stop database Stop() error //Set set value by given key Set(key []byte, value []byte) error //Get get value by given key Get(key []byte) ([]byte, error) //Delete delete value by given key Delete(key []byte) error //Next return keys after iter not more than given limit //Empty iter (nil or 0 length []byte) will start a new search //Return keyvalue ,newiter and any error if raised. //Empty iter (nil or 0 length []byte) will be returned if no more keys Next(iter []byte, limit int) (kv []*herbdata.KeyValue, newiter []byte, err error) //Prev return keys before iter not more than given limit //Empty iter (nil or 0 length []byte) will start a new search //Return keys ,newiter and any error if raised. //Empty iter (nil or 0 length []byte) will be returned if no more keys Prev(iter []byte, limit int) (kv []*herbdata.KeyValue, newiter []byte, err error) //SetWithTTL set value by given key and ttl in second. SetWithTTL(key []byte, value []byte, ttlInSecond int64) error //SetWithExpired set value by given key and expired timestamp. SetWithExpired(key []byte, value []byte, expired int64) error //Begin begin new transaction Begin() (Transaction, error) //Insert insert value with given key. //Insert will fail if data with given key exists. //Return if operation success and any error if raised Insert(Key []byte, value []byte) (bool, error) //InsertWithTTL insert value with given key and ttl in second. //Insert will fail if data with given key exists. //Return if operation success and any error if raised InsertWithTTL(Key []byte, value []byte, ttlInSecond int64) (bool, error) //Update update value with given key. //Update will fail if data with given key does nto exist. //Return if operation success and any error if raised Update(key []byte, value []byte) (bool, error) //UpdateWithTTL update value with given key and ttl in second. //Update will fail if data with given key does nto exist. //Return if operation success and any error if raised UpdateWithTTL(key []byte, value []byte, ttlInSecond int64) (bool, error) //SetCounter set counter value with given key SetCounter(key []byte, value int64) error //SetCounterWithTTL set counter value with given key and ttl SetCounterWithTTL(key []byte, value int64, ttlInSecond int64) error //IncreaseCounter increace counter value with given key and increasement. //Value not existed coutn as 0. //Return final value and any error if raised. IncreaseCounter(key []byte, incr int64) (int64, error) //IncreaseCounterWithTTL increace counter value with given key ,increasement,and ttl. //Value not existed coutn as 0. //Return final value and any error if raised. IncreaseCounterWithTTL(key []byte, incr int64, ttlInSecond int64) (int64, error) //GetCounter get counter value with given key //Value not existed coutn as 0. GetCounter(key []byte) (int64, error) //DeleteCounter delete counter value with given key DeleteCounter(key []byte) error //Features return supported features Features() Feature //IsolationLevel transaction isolation level //Return 0 if transaction is not supported IsolationLevel() IsolationLevel //SetErrorHanlder set error hanlder SetErrorHanlder(func(error)) }
Driver key value database driver interface
func NewDriver ¶
NewDriver create new driver with given name loader. Reutrn driver created and any error if raised.
func PassthroughFactory ¶
PassthroughFactory passthrough driver factory
type Feature ¶
type Feature int64
Feature key-value database feature type
func (Feature) SupportAll ¶
SupportAll check if all given features are supported
func (Feature) SupportAny ¶
SupportAny check if any one of given features are supported
type Nop ¶
type Nop struct{}
Nop key-value database driver All method except "Close" will raise an ErrFeatureNotSupported error. All key-value database driver should implement Nop driver
func (Nop) DeleteCounter ¶
DeleteCounter delete counter value with given key
func (Nop) GetCounter ¶
GetCounter get counter value with given key Value not existed coutn as 0.
func (Nop) IncreaseCounter ¶
IncreaseCounter increace counter value with given key and increasement. Value not existed coutn as 0. Return final value and any error if raised.
func (Nop) IncreaseCounterWithTTL ¶
IncreaseCounterWithTTL increace counter value with given key ,increasement,and ttl in second Value not existed coutn as 0. Return final value and any error if raised.
func (Nop) Insert ¶
Insert insert value with given key. Insert will fail if data with given key exists. Return if operation success and any error if raised
func (Nop) InsertWithTTL ¶
InsertWithTTL insert value with given key and ttl in second. Insert will fail if data with given key exists. Return if operation success and any error if raised
func (Nop) IsolationLevel ¶
func (n Nop) IsolationLevel() IsolationLevel
IsolationLevel transaction isolation level
func (Nop) SetCounter ¶
SetCounter set counter value with given key
func (Nop) SetCounterWithTTL ¶
SetCounterWithTTL set counter value with given key and ttl in second
func (Nop) SetErrorHanlder ¶
SetErrorHanlder set error hanlder
func (Nop) SetWithExpired ¶
SetWithExpired set value by given key and expired timestamp.
func (Nop) SetWithTTL ¶
SetWithTTL set value by given key and ttl in second
type Transaction ¶
type Transaction interface { //Rollback rollback transaction. //Discard all operations in transaction. Rollback() error //Commit commit transaction //Apply all operaions in transaction. Commit() error //Set set value by given key Set(key []byte, value []byte) error //Get get value by given key Get(key []byte) ([]byte, error) //Delete delete value by given key Delete(key []byte) error //SetWithTTL set value by given key and ttl in Second SetWithTTL(key []byte, value []byte, ttlInSecond int64) error //IsolationLevel transaction isolation level IsolationLevel() IsolationLevel }
Transaction datanase transaction interface