Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pantani/redis
Simple abstraction for Go-Redis.
https://github.com/pantani/redis
cache database go go-redis golang redis
Last synced: about 7 hours ago
JSON representation
Simple abstraction for Go-Redis.
- Host: GitHub
- URL: https://github.com/pantani/redis
- Owner: Pantani
- License: mit
- Created: 2020-03-28T15:48:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-26T01:32:00.000Z (over 3 years ago)
- Last Synced: 2024-06-20T11:58:51.747Z (5 months ago)
- Topics: cache, database, go, go-redis, golang, redis
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Reference](https://pkg.go.dev/badge/github.com/Pantani/redis.svg)](https://pkg.go.dev/github.com/Pantani/redis)
[![codecov](https://codecov.io/gh/Pantani/redis/branch/master/graph/badge.svg?token=8IHUB3K2Q7)](https://codecov.io/gh/Pantani/redis)# Simple abstraction for [Go-Redis](github.com/go-redis/redis).
Simple abstraction using generic interfaces for [Go-Redis](github.com/go-redis/redis).
Initialize the database:
```go
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:
```go
var result CustomObject
err := s.GetObject("key", &result)
```- Add value
```go
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:
```go
err := s.DeleteObject("table", "key")
```### Hash Map
Redis hash map abstraction
- Get all values from a hash map table:
```go
result, err := s.GetAllHMObjects("table")
```- Get value from a hash map table:
```go
var result CustomObject
err := s.GetHMObject("table", "key", &result)
```- Add value to a hash map table:
```go
data := CustomObject{Name: "name", Id: "id"}
err := s.AddHMObject("table", "key", data)
```- Delete value from a hash map table:
```go
err := s.DeleteHMObject("table", "key")
```