dao

package
v0.0.0-...-3168f03 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dao

type Dao struct {
	InfluxDB influx.Client
	Redis    *redis.Client
}

Dao object

func New

func New(c *conf.Config) (dao *Dao)

New init DAO

func (*Dao) Close

func (dao *Dao) Close()

Close will disconnect from DB

func (*Dao) GetQueryCache

func (dao *Dao) GetQueryCache(c context.Context, m *model.BtcQuery) ([]*model.BtcResponse, bool)

GetQueryCache will try to get result of query in redis if redis is disabled or no result found or an error occurred, the second return value will be false

func (*Dao) InsertCoin

func (dao *Dao) InsertCoin(c context.Context, m *model.BtcData) error

InsertCoin save a new record in db amount and timestamp will be saved in int64, timestamp is additional variable to help query the target data.

func (*Dao) Ping

func (dao *Dao) Ping(ctx context.Context) (err error)

Ping check the connection of DB.

func (*Dao) QueryCoin

func (dao *Dao) QueryCoin(c context.Context, m *model.BtcQuery) ([][]interface{}, error)

QueryCoin will return the result of query

func (*Dao) SetQueryCache

func (dao *Dao) SetQueryCache(c context.Context, m *model.BtcQuery, v []*model.BtcResponse) error

SetQueryCache will store the result of query in redis if redis is available Since the result is not real-time sensitive, we can set the expiration time to 5 minutes to reduce the pressure of database.

Jump to

Keyboard shortcuts

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