db

package
v0.0.0-...-c6e3130 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 5 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a key is passed that is not in the in-memory database

Functions

This section is empty.

Types

type DB

type DB interface {
	// Save saves the given model under the given key. Example usage:
	//
	//	err := mydb.Save(models.NewAppKey("app123"), models.App{Name:"myapp"})
	//	// check error and continue
	Save(models.Key, models.Model) error
	// Delete deletes the model under the given key. After delete exits successfully, both the key and the model under it should be removed entirely. Example usage:
	//
	//	err := mydb.Delete(models.NewAppKey("app123"))
	//	// check error and continue
	Delete(models.Key) error
	// Get gets the model under the given key and writes it into the given model. Callers should pass a pointer to a model implementation so that this func can unmarshal the model from the database and write it into the given model. Example usage:
	//
	//	app := &models.App{}
	//	if err := mydb.Get(models.NewAppKey("app123"), app); err != nil {
	//		fmt.Println("error getting model!")
	//		return
	//	}
	//	// use app
	Get(models.Key, models.Model) error
}

DB is the generic key/value interface for databases that work with this server

type Mem

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

Mem is an in-memory only implementation of DB

func NewMem

func NewMem() *Mem

NewMem initializes and returns an empty Mem database

func (*Mem) Delete

func (m *Mem) Delete(key models.Key) error

Delete is the interface implementation. Never returns an error, even if the key didn't exist

func (*Mem) Get

func (m *Mem) Get(key models.Key, model models.Model) error

Get is the interface implementation. Returns ErrNotFound if no such key existed. Callers should pass a pointer to a model so that Get can write the fetched model into it

func (*Mem) Save

func (m *Mem) Save(key models.Key, model models.Model) error

Save is the interface implementation. Overwrites existing keys and never returns an error

type Redis

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

RedisRedis is a db.DB implementation that talks to Redis

func NewRedis

func NewRedis(cl *redis.Client) *Redis

NewRedis initializes and returns a redis DB using the given raw redis.v3 client

func (*Redis) Delete

func (r *Redis) Delete(k models.Key) error

Delete is the interface implementation

func (*Redis) Get

func (r *Redis) Get(k models.Key, m models.Model) error

Get is the interface implementation

func (*Redis) Save

func (r *Redis) Save(k models.Key, m models.Model) error

Save is the interface implementation

Jump to

Keyboard shortcuts

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