storage

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cron

func Cron(storage StorageInterface, shutdowner fx.Shutdowner) error

Cron entrypoint

Types

type KeyValue

type KeyValue struct {
	ID    string  `gorm:"primaryKey,type:varchar(64)"`
	Value float64 `gorm:"type:decimal(40,15);"`
	TTL   int64   `gorm:"default:0"`
}

KeyValue represent key-value storage in ORM

type PostgresStorage

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

PostgresStorage pgsql instance

func (*PostgresStorage) Cron

func (store *PostgresStorage) Cron() error

func (*PostgresStorage) Get

func (store *PostgresStorage) Get(key string) (value float64, err error)

func (*PostgresStorage) Incr

func (store *PostgresStorage) Incr(key string, value float64) (result float64, err error)

func (*PostgresStorage) SetNX

func (store *PostgresStorage) SetNX(key string, value float64, ttl time.Duration) (err error)

type RedisStorage

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

RedisStorage redis client

func (*RedisStorage) Cron

func (store *RedisStorage) Cron() error

func (*RedisStorage) Get

func (store *RedisStorage) Get(key string) (value float64, err error)

func (*RedisStorage) Incr

func (store *RedisStorage) Incr(key string, value float64) (result float64, err error)

func (*RedisStorage) SetNX

func (store *RedisStorage) SetNX(key string, value float64, ttl time.Duration) (err error)

type StorageInterface

type StorageInterface interface {
	// Cron method for execute storage-specific cron-jobs, e.g. cleanup ttl
	Cron() error
	// Get return record from storage, or error
	Get(key string) (float64, error)
	// SetNX create record if not exists
	SetNX(key string, value float64, ttl time.Duration) error
	// Incr atomic increment or decrement
	Incr(key string, value float64) (float64, error) //float64 precision is enough for votes
}

func CreatePostgres

func CreatePostgres(config config.Config) (storage StorageInterface, err error)

CreatePostgres create new instance of PostgresStorage

func CreateRedis

func CreateRedis(config config.Config) (storage StorageInterface, err error)

CreateRedis create instance of RedisStorage

Jump to

Keyboard shortcuts

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