Extracted Cache dependencies
This commit is contained in:
parent
40f1687972
commit
1f69282c73
4 changed files with 15 additions and 28 deletions
|
|
@ -28,7 +28,7 @@ func main() {
|
||||||
GroupId: groupId,
|
GroupId: groupId,
|
||||||
ConfirmationString: os.Getenv("VK_CONFIRMATION_STRING"),
|
ConfirmationString: os.Getenv("VK_CONFIRMATION_STRING"),
|
||||||
DictPath: "./assets/additional_cards.json",
|
DictPath: "./assets/additional_cards.json",
|
||||||
Cache: caching.GetClient(),
|
Cache: caching.NewClient("redis:6379", "", time.Hour*24, 0),
|
||||||
InfoFetcher: &cardsinfo.Fetcher{},
|
InfoFetcher: &cardsinfo.Fetcher{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetClient(t *testing.T) {
|
func TestGetClient(t *testing.T) {
|
||||||
c := GetClient()
|
c := NewClient("addr", "123", time.Hour, 1)
|
||||||
assert.Equal(t, CacheExpiration, c.Expiration)
|
assert.Equal(t, time.Hour, c.Expiration)
|
||||||
assert.Equal(t, 0, c.Storage.Options().DB)
|
assert.Equal(t, 1, c.Storage.Options().DB)
|
||||||
assert.Equal(t, HostName, c.Storage.Options().Addr)
|
assert.Equal(t, "addr", c.Storage.Options().Addr)
|
||||||
assert.Equal(t, Password, c.Storage.Options().Password)
|
assert.Equal(t, "123", c.Storage.Options().Password)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetSet(t *testing.T) {
|
func TestGetSet(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -10,19 +10,15 @@ type CacheClient struct {
|
||||||
Expiration time.Duration
|
Expiration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetClient() *CacheClient {
|
func NewClient(addr string, passwd string, expiration time.Duration, db int) *CacheClient {
|
||||||
client := new(CacheClient)
|
return &CacheClient{
|
||||||
client.Init()
|
Storage: redis.NewClient(&redis.Options{
|
||||||
return client
|
Addr: addr,
|
||||||
|
Password: passwd,
|
||||||
|
DB: db,
|
||||||
|
}),
|
||||||
|
Expiration: expiration,
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
func (client *CacheClient) Set(key string, value string) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
package caching
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const HostName = "redis:6379"
|
|
||||||
const Password = ""
|
|
||||||
const CacheExpiration = time.Hour * 24
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue