databroker server backend config (#1127)

* config,docs: add databroker storage backend configuration

* cache: allow configuring which backend storage to use

Currently supported types are "memory", "redis".
This commit is contained in:
Cuong Manh Le 2020-07-23 10:42:43 +07:00 committed by GitHub
parent c9182f757e
commit 1640151bc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 99 additions and 6 deletions

View file

@ -8,17 +8,22 @@ var (
DefaultDeletePermanentlyAfter = time.Hour
// DefaultBTreeDegree is the default number of items to store in each node of the BTree.
DefaultBTreeDegree = 8
// DefaultStorageType is the default storage type that Server use
DefaultStorageType = "memory"
)
type serverConfig struct {
deletePermanentlyAfter time.Duration
btreeDegree int
deletePermanentlyAfter time.Duration
btreeDegree int
storageType string
storageConnectionString string
}
func newServerConfig(options ...ServerOption) *serverConfig {
cfg := new(serverConfig)
WithDeletePermanentlyAfter(DefaultDeletePermanentlyAfter)(cfg)
WithBTreeDegree(DefaultBTreeDegree)(cfg)
WithStorageType(DefaultStorageType)(cfg)
for _, option := range options {
option(cfg)
}
@ -43,3 +48,17 @@ func WithDeletePermanentlyAfter(dur time.Duration) ServerOption {
cfg.deletePermanentlyAfter = dur
}
}
// WithStorageType sets the storage type.
func WithStorageType(typ string) ServerOption {
return func(cfg *serverConfig) {
cfg.storageType = typ
}
}
// WithStorageConnectionString sets the DSN for storage.
func WithStorageConnectionString(connStr string) ServerOption {
return func(cfg *serverConfig) {
cfg.storageConnectionString = connStr
}
}