redis

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 5 Imported by: 0

README

Simple abstraction for Go-Redis.

Simple abstraction using generic interfaces for Go-Redis.

Initialize the database:

import "github.com/Pantani/redis"

cache := redis.New("localhost:6379", "password", 0)
if err != nil {
    panic("Cannot initialize the redis storage")
}
if !storage.IsReady() {
    panic("redis storage is not ready")
}

Fetching Objects:

  • Get value:
var result CustomObject
err := s.GetObject("key", &result)
  • Add value
data := CustomObject{Name: "name", Id: "id"}
err := s.AddObject("key", data, 0)

// with expiration time
err := s.AddObject("key", data, 10 * time.Second)
  • Delete value:
err := s.DeleteObject("table", "key")
Hash Map

Redis hash map abstraction

  • Get all values from a hash map table:
result, err := s.GetAllHMObjects("table")
  • Get value from a hash map table:
var result CustomObject
err := s.GetHMObject("table", "key", &result)
  • Add value to a hash map table:
data := CustomObject{Name: "name", Id: "id"}
err := s.AddHMObject("table", "key", data)
  • Delete value from a hash map table:
err := s.DeleteHMObject("table", "key")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Redis

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

func New

func New(host, password string, dbIndex int) (*Redis, error)

New returns a new database connection and an error if occurs.

func (*Redis) AddHMObject

func (db *Redis) AddHMObject(ctx context.Context, entity, key string, value interface{}) error

AddHMObject add an object to a hash map table. It returns an error if occurs.

func (*Redis) AddObject

func (db *Redis) AddObject(ctx context.Context, key string, value interface{}, duration time.Duration) error

AddObject add object for a key. It returns an error if occurs.

func (*Redis) DeleteHMObject

func (db *Redis) DeleteHMObject(ctx context.Context, entity, key string) error

DeleteHMObject delete an object from a hash map table. It returns an error if occurs.

func (*Redis) DeleteObject

func (db *Redis) DeleteObject(ctx context.Context, key string) error

DeleteObject delete object from key. It returns an error if occurs.

func (*Redis) GetAllHMObjects

func (db *Redis) GetAllHMObjects(ctx context.Context, entity string) (map[string]string, error)

GetAllHMObjects get all objects from a hash map table. It returns the objects and an error if occurs.

func (*Redis) GetHMObject

func (db *Redis) GetHMObject(ctx context.Context, entity, key string, value interface{}) error

GetHMObject get an object from a hash map table. It returns an error if occurs.

func (*Redis) GetObject

func (db *Redis) GetObject(ctx context.Context, key string, value interface{}) error

GetObject get object from key. It returns an error if occurs.

func (*Redis) IsReady

func (db *Redis) IsReady(ctx context.Context) bool

IsReady verify the database is ready. It returns true if ready.

Jump to

Keyboard shortcuts

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