tempdb

package module
v0.0.0-...-f0a5044 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2018 License: MIT Imports: 6 Imported by: 0

README

Tempdb

  • TempDB is Redis-backed temporary key-value store for Go.
  • Useful for storing temporary data such as login codes, authentication tokens, and temporary passwords.
  • A Go version of tempDB

Installation

go get -u github.com/rafaeljesus/tempdb

Usage

Tempdb stores an expiring (or non-expiring) key/value pair in Redis.

Tempdb

import "github.com/rafaeljesus/tempdb"

temp, err := tempdb.New(tempdb.Options{
  Addr: "localhost:6379",
  Password: "foo",
})

if err = temp.Insert("key", "value", 0); err != nil {
  // handle failure insert key
}

if err = temp.Insert("key2", "value", time.Hour); err != nil {
  // handle failure insert key
}

if err = temp.Find("key"); err != nil {
  // handle failure to get value
}

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Badges

Build Status Go Report Card Go Doc


GitHub @rafaeljesus  ·  Medium @_jesus_rafael  ·  Twitter @_jesus_rafael

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyRequired is returned when key is not passed as parameter in tempdb.Config.
	ErrKeyRequired = errors.New("creating a new tempdb requires a non-empty key")
	// ErrValueRequired is returned when value is not passed as parameter in tempdb.Config.
	ErrValueRequired = errors.New("creating a new tempdb requires a non-empty value")
)

Functions

This section is empty.

Types

type Options

type Options struct {
	Network            string
	Addr               string
	Dialer             func() (net.Conn, error)
	Password           string
	DB                 int
	MaxRetries         int
	DialTimeout        time.Duration
	ReadTimeout        time.Duration
	WriteTimeout       time.Duration
	PoolSize           int
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration
	ReadOnly           bool
	TLSConfig          *tls.Config
}

Options carries the different variables to tune a newly started redis client, it exposes the same configuration available from https://godoc.org/gopkg.in/redis.v5#Options go client.

type Tempdb

type Tempdb struct {
	*redis.Client
}

Tempdb stores an expiring (or non-expiring) key/value pair in Redis.

func New

func New(o Options) (*Tempdb, error)

New returns a new temp configured with the variables from the options parameter, or returning an non-nil err if an error occurred while creating redis client.

func (*Tempdb) Find

func (t *Tempdb) Find(key string) (string, error)

Find the value associated with the key.

func (*Tempdb) Insert

func (t *Tempdb) Insert(key, value string, expires time.Duration) error

Insert a key/value pair with an optional expiration time.

Jump to

Keyboard shortcuts

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