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