remon

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

README

remon

redis cached mongodb based nosql database

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExists = errors.New("remon: already exists")
	ErrNotFound      = errors.New("remon: not found")
	ErrMailFull      = errors.New("remon: mail full")
)

Functions

This section is empty.

Types

type Client added in v0.1.4

type Client interface {
	// get stat info
	Metrics() *Metrics

	// Get value from remon
	// If cache miss, load from database
	Get(ctx context.Context, key string, opts ...GetOption) (rev int64, val string, err error)

	// Set value to remon
	// Value will be saved to cache and synced to database later automatically
	Set(ctx context.Context, key, val string) (rev int64, err error)

	// Add value to remon
	// If key already exists, return ErrAlreadyExists
	// If add success, the rev must be 1
	Add(ctx context.Context, key, val string) (err error)
	// contains filtered or unexported methods
}

func New

func New(rdb RedisClient, mdb *mongo.Client, opts ...Option) Client

func NewClient added in v0.1.4

func NewClient(rdb RedisClient, mdb *mongo.Client, opts ...Option) Client

type GetOption added in v0.1.4

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

get method xOptions

func AddIfNotFound added in v0.1.4

func AddIfNotFound(v string) GetOption

type Mail added in v0.1.4

type Mail struct {
	// auto-generated seq to identify a mail
	Id int64 `msgpack:"id"`
	// mail payload
	Val string `msgpack:"val"`
}

type MailClient added in v0.1.4

type MailClient interface {
	// list mails
	List(ctx context.Context, key string) (_ []*Mail, err error)
	// push mail in
	Push(ctx context.Context, key, val string, opts ...PushOption) (id int64, err error)
	// pull mail(s) out
	Pull(ctx context.Context, key string, ids ...int64) (pulled []int64, err error)
	// clean all mails
	Clean(ctx context.Context, key string) (err error)
}

func NewMailClient added in v0.1.4

func NewMailClient(rm Client) MailClient

type MapKeyFunc added in v0.1.4

type MapKeyFunc func(key string) (db, collection, _id string)

Redis(key) -> Mongo(db,collection,_id)

type Metrics added in v0.1.4

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

client wide statistics

func (*Metrics) CacheHit added in v0.1.4

func (m *Metrics) CacheHit() int64

func (*Metrics) CacheMiss added in v0.1.4

func (m *Metrics) CacheMiss() int64

func (*Metrics) DataError added in v0.1.4

func (m *Metrics) DataError() int64

func (*Metrics) MongoError added in v0.1.4

func (m *Metrics) MongoError() int64

func (*Metrics) RedisError added in v0.1.4

func (m *Metrics) RedisError() int64

func (*Metrics) Reset added in v0.1.4

func (m *Metrics) Reset()

type OnSyncErrorFunc added in v0.1.4

type OnSyncErrorFunc func(err error) time.Duration

同步失败回调函数

type OnSyncIdleFunc added in v0.1.4

type OnSyncIdleFunc func() time.Duration

同步空闲回调函数

type OnSyncSaveFunc added in v0.1.4

type OnSyncSaveFunc func(key string) time.Duration

同步成功回调函数

type Option

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

func OnSyncError added in v0.1.4

func OnSyncError(f OnSyncErrorFunc) Option

func OnSyncIdle added in v0.1.4

func OnSyncIdle(f OnSyncIdleFunc) Option

func OnSyncSave added in v0.1.4

func OnSyncSave(f OnSyncSaveFunc) Option

func WithKeyMap added in v0.1.4

func WithKeyMap(f MapKeyFunc) Option

type PushOption

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

func WithCapacity

func WithCapacity(v int) PushOption

func WithPushStrategy added in v0.1.4

func WithPushStrategy(v PushStrategy) PushOption

type PushStrategy added in v0.1.4

type PushStrategy int

push method options

const (
	RejectOnFull     PushStrategy = 0
	PullOldestOnFull PushStrategy = 1
)

type RedisClient

type RedisClient interface {
	EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *redis.Cmd
	ScriptLoad(ctx context.Context, script string) *redis.StringCmd
}

type Syncer added in v0.1.4

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

func NewSyncer added in v0.1.4

func NewSyncer(rdb RedisClient, mdb *mongo.Client, opts ...Option) *Syncer

func (*Syncer) Serve added in v0.1.4

func (s *Syncer) Serve()

func (*Syncer) Stop added in v0.1.4

func (s *Syncer) Stop()

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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