db

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LockOn sets the lock
	LockOn = "locked"
	// LockOff unsets the lock
	LockOff = "unlocked"
	// TTL for the lock
	TTL = 30 * time.Second
	// TTLRefreshInterval intervals for refreshing the TTL of the lock
	TTLRefreshInterval = 10 * time.Second
)

Variables

This section is empty.

Functions

func Password

func Password(p string) func(*redis.Options)

Password functional option

Types

type DB

type DB interface {
	GetOne(table string, key string) (string, error)
	AddOne(table string, key string, value string) error
	GetAllRecords(table string) (map[string]string, int, error)
	DeleteOne(table string, key string) error
	DropTable(table string) error
	PipelineAddOne(table, key string, values string)
	PipelineExec() error
	Close() error
	Health() error
}

DB is the interface that will allow to use different backends for storing data into the database

type Redis

type Redis struct {
	*redis.Client
	Pipeliner redis.Pipeliner
}

Redis is a wrapper struct around Redis official package

func NewRedisClient

func NewRedisClient(addr string, opts ...func(*redis.Options)) (*Redis, error)

NewRedisClient creates and open a new connection to Redis

func (*Redis) AddOne

func (db *Redis) AddOne(table, key string, values string) error

AddOne store the key/value in the redis

func (*Redis) Close

func (db *Redis) Close() error

Close will be called as defer from the dependency whenever it's needed to close the connection

func (*Redis) DeleteOne

func (db *Redis) DeleteOne(table, key string) error

DeleteOne deletes a key from a table

func (*Redis) DropTable

func (db *Redis) DropTable(table string) error

DropTable deletes all the keys and the table itself

func (*Redis) ExtendTTL

func (db *Redis) ExtendTTL(key string) error

ExtendTTL ddd

func (*Redis) GetAllRecords

func (db *Redis) GetAllRecords(table string) (map[string]string, int, error)

GetAllRecords returns all the records from that table the map[string]string represents the signalID -> recommendations encoded

func (*Redis) GetOne

func (db *Redis) GetOne(table, key string) (string, error)

GetOne returns the value associated with that key

func (*Redis) Health

func (db *Redis) Health() error

Health will return a ping based on whether the database is healthy

func (*Redis) Lock

func (db *Redis) Lock(key string) (bool, error)

Lock allows to lock the resource

func (*Redis) PipelineAddOne

func (db *Redis) PipelineAddOne(table, key string, values string)

PipelineAddOne queues the HSET operation to the pipeline

func (*Redis) PipelineExec

func (db *Redis) PipelineExec() error

PipelineExec executes the commands in the Pipeline

func (*Redis) Unlock

func (db *Redis) Unlock(key string) (bool, error)

Unlock unlocks the the key

type S3Bucket

type S3Bucket struct {
	Bucket string
	ACL    string
}

S3Bucket holds the information of the bucket

type S3Client

type S3Client struct {
	Service *s3.S3
	Bucket  string
}

S3Client is the object that wraps around the official aws SDK

func NewS3Client

func NewS3Client(bucket *S3Bucket, sess *session.Session) *S3Client

NewS3Client is a wrapper object around the official aws s3 client

func (*S3Client) CreateS3Bucket

func (c *S3Client) CreateS3Bucket(bucket *S3Bucket) (bool, error)

CreateS3Bucket creates a bucket It returns false if the bucket exists, true otherwise

func (*S3Client) DeleteS3AllObjects

func (c *S3Client) DeleteS3AllObjects(bucket *S3Bucket) error

DeleteS3AllObjects all objects within a bucket (this is not the most efficient way)

func (*S3Client) DeleteS3Bucket

func (c *S3Client) DeleteS3Bucket(bucket *S3Bucket) (bool, error)

DeleteS3Bucket creates a bucket It returns false if the bucket exists, true otherwise

func (*S3Client) ExistsObject

func (c *S3Client) ExistsObject(key string) bool

ExistsObject test if the specified key exists in the bucket It returns true if the key exists, false otherwise

func (*S3Client) GetObject

func (c *S3Client) GetObject(key string) (*io.ReadCloser, error)

GetObject returns the specified object-key from the selected bucket

func (*S3Client) UploadS3File

func (c *S3Client) UploadS3File(fileDir string, bucket *S3Bucket) error

UploadS3File a file to S3

Jump to

Keyboard shortcuts

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