Skip to content

Pantani/redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2705204 · Feb 26, 2021

History

19 Commits
Feb 26, 2021
Mar 28, 2020
Feb 26, 2021
Feb 26, 2021
Feb 26, 2021
Feb 26, 2021
Sep 16, 2020
Sep 18, 2020

Repository files navigation

Go Reference codecov

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")