db

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package db contains database usage methods.

Index

Constants

View Source
const (
	// KeyLen is a number of bytes for random db key.
	KeyLen = 64
)

Variables

This section is empty.

Functions

func Delete added in v1.2.0

func Delete(key string, c redis.Conn) (bool, error)

Delete removes data struct by the key.

func GetDbPool added in v0.0.2

func GetDbPool(c *Cfg) (*redis.Pool, error)

GetDbPool creates new Redis db connections pool.

func IsOk added in v1.1.0

func IsOk(conn redis.Conn) bool

IsOk checks db is available using redis PING command.

Types

type Cfg added in v0.0.2

type Cfg struct {
	Host     string `json:"host"`
	Port     uint   `json:"port"`
	Network  string `json:"network"`
	Db       int    `json:"db"`
	Timeout  int64  `json:"timeout"`
	Password string `json:"password"`
	IndleCon int    `json:"indlecon"`
	MaxCon   int    `json:"maxcon"`
	// contains filtered or unexported fields
}

Cfg is configuration redis settings.

func (*Cfg) RedisAddr added in v0.0.2

func (c *Cfg) RedisAddr() string

RedisAddr returns redis service's net address.

type Item

type Item struct {
	Content  string
	TTL      int
	Times    int
	Password string
	Key      string
	// contains filtered or unexported fields
}

Item is data for new saving.

func New

func New(r *http.Request, ttl, times int) (*Item, error)

New checks POST form data anb returns new item for saving.

func (*Item) CheckPassword

func (item *Item) CheckPassword(c redis.Conn) (bool, error)

CheckPassword checks that password is correct.

func (*Item) Exists

func (item *Item) Exists(c redis.Conn) (bool, error)

Exists returns true if item exists in database.

func (*Item) GetURL

func (item *Item) GetURL(r *http.Request, secure bool) *url.URL

GetURL returns item's URL.

func (*Item) Read

func (item *Item) Read(c redis.Conn, skey []byte) (bool, error)

Read gets data from database. Expected it is called after Exists and CheckPassword.

func (*Item) Save

func (item *Item) Save(c redis.Conn, skey []byte) error

Save saves the item to database.

Jump to

Keyboard shortcuts

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