Skip to content

Latest commit

 

History

History
68 lines (52 loc) · 1.45 KB

README.md

File metadata and controls

68 lines (52 loc) · 1.45 KB

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