Extracted Cache dependencies

This commit is contained in:
Artyom Belousov 2021-02-07 10:44:26 +03:00
parent 40f1687972
commit 1f69282c73
4 changed files with 15 additions and 28 deletions

View file

@ -10,19 +10,15 @@ type CacheClient struct {
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 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) {