mtg-price-bot/internal/caching/client.go
Artyom Belousov 40f1687972 Added Fetcher
2021-02-07 10:33:16 +03:00

34 lines
646 B
Go

package caching
import (
"github.com/go-redis/redis"
"time"
)
type CacheClient struct {
Storage *redis.Client
Expiration time.Duration
}
func GetClient() *CacheClient {
client := new(CacheClient)
client.Init()
return client
}
func (client *CacheClient) Init() {
client.Storage = redis.NewClient(&redis.Options{
Addr: HostName,
Password: Password,
DB: 0,
})
client.Expiration = CacheExpiration
}
func (client *CacheClient) Set(key string, value string) {
client.Storage.Set(key, value, client.Expiration)
}
func (client *CacheClient) Get(key string) (string, error) {
return client.Storage.Get(key).Result()
}