remon

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

README

remon

redis cached mongodb based nosql database

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed = errors.New("remon: closed")
)
View Source
var (
	// exported errors
	ErrNotExist = errors.New("remon: not exist")
)

Functions

func ScriptLoad

func ScriptLoad(r scripter) (err error)

Types

type DB

type DB = ReMon

type Data added in v0.1.1

type Data struct {
	// sync/load
	Version int64 `msgpack:"version" bson:"version"`
	// for get/set
	Value string `msgpack:"value" bson:"value"`
	// for list
	List struct {
		Inc int64             `msgpack:"inc" bson:"inc"` // id auto increment
		Que []string          `msgpack:"que" bson:"que"` // ids by push order
		Map map[string]string `msgpack:"map" bson:"map"` // id to value
	} `msgpack:"list" bson:"list"`
}

func (Data) String added in v0.1.1

func (d Data) String() string

type Elem added in v0.1.1

type Elem struct {
	Id    string
	Value string
}

list element

type KeyMappingStrategy

type KeyMappingStrategy interface {
	MapKey(string) (_, _, _ string)
}

map redis key to mongodb (database,collection,_id)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithKeyMappingStrategy

func WithKeyMappingStrategy(v KeyMappingStrategy) Option

func WithKeyMappingStrategyFunc

func WithKeyMappingStrategyFunc(v func(string) (_, _, _ string)) Option

func WithSyncLimit added in v0.1.1

func WithSyncLimit(v int) Option

func WithVolatileTTL

func WithVolatileTTL(v time.Duration) Option

type PushOption

type PushOption interface {
	// contains filtered or unexported methods
}

func WithCapacity

func WithCapacity(capacity int) PushOption

type ReMon

type ReMon struct {
	// contains filtered or unexported fields
}

func New

func New(r RedisClient, m *mongo.Client, opts ...Option) (x *ReMon)

func (*ReMon) EvalVarJSON

func (x *ReMon) EvalVarJSON(ctx context.Context, key, src string) (ret int, value string, err error)

Eval custom lua script on json value If src cannot be trusted, set lua-time-limit to a small value

func (*ReMon) Get

func (x *ReMon) Get(ctx context.Context, key string) (value string, err error)

Get value from remon, if redis cache miss, load from mongo

func (*ReMon) GetList added in v0.1.1

func (x *ReMon) GetList(ctx context.Context, key string) (list []Elem, err error)

Get list value from remon, if redis cache miss, load from mongodb

func (*ReMon) Pull added in v0.1.1

func (x *ReMon) Pull(ctx context.Context, key string, ids []string) (n int, err error)

Pull element(s) from list

func (*ReMon) Push added in v0.1.1

func (x *ReMon) Push(ctx context.Context, key string, values []string, opts ...PushOption) (err error)

Push element(s) to list

func (*ReMon) Set

func (x *ReMon) Set(ctx context.Context, key, value string) (err error)

Set value to redis cache, data will be saved to mongo by sync

func (*ReMon) Stat

func (x *ReMon) Stat() *Stat

type RedisClient

type RedisClient interface {
	Pipeline() redis.Pipeliner
	ProcessContext(context.Context, redis.Cmder) error
	// contains filtered or unexported methods
}

type Stat

type Stat struct {
	RedisHit   int64 // cache hit counter
	RedisMiss  int64 // cache miss counter
	RedisError int64 // cache error counter
	MongoError int64 // db error counter
	DataError  int64 // data error counter
}

type Sync

type Sync struct {
	// contains filtered or unexported fields
}

func NewSync

func NewSync(r RedisClient, m *mongo.Client, opts ...Option) *Sync

func (*Sync) Close

func (x *Sync) Close()

func (*Sync) Hook

func (x *Sync) Hook(hookers ...SyncHooker)

func (*Sync) Serve

func (x *Sync) Serve() (err error)

func (*Sync) Shutdown

func (x *Sync) Shutdown(ctx context.Context) (err error)

close sync gracefully, waiting all write complete

type SyncHooker

type SyncHooker interface {
	// contains filtered or unexported methods
}

func SyncOnError

func SyncOnError(f SyncOnErrorFunc) SyncHooker

func SyncOnSave

func SyncOnSave(f SyncOnSaveFunc) SyncHooker

type SyncOnErrorFunc

type SyncOnErrorFunc func(err error) error

type SyncOnSaveFunc

type SyncOnSaveFunc func(key string, version int64)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL