Extracted scenario

This commit is contained in:
Artyom Belousov 2021-06-06 11:00:50 +03:00
parent c02435ccaa
commit cc2058090c
13 changed files with 235 additions and 173 deletions

31
internal/caching/cache.go Normal file
View file

@ -0,0 +1,31 @@
package caching
import (
"time"
"github.com/go-redis/redis"
)
type CacheClient struct {
Storage *redis.Client
Expiration time.Duration
}
func NewClient(addr string, passwd string, expiration time.Duration, db int) *CacheClient {
return &CacheClient{
Storage: redis.NewClient(&redis.Options{
Addr: addr,
Password: passwd,
DB: db,
}),
Expiration: expiration,
}
}
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()
}