Added redis support

This commit is contained in:
Artyom Belousov 2019-05-16 14:58:24 +03:00
parent 577664c034
commit 98a8040246
4 changed files with 101 additions and 1 deletions

36
tests/cache_test.go Normal file
View file

@ -0,0 +1,36 @@
package tests
import (
"github.com/flygrounder/mtg-price-vk/caching"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestGetSet(t *testing.T) {
client := getTestClient()
keyName := "test_key"
value := "test_value"
client.Set(keyName, value)
val, err := client.Get(keyName)
assert.Nil(t, err)
assert.Equal(t, value, val)
}
func TestExpiration(t *testing.T) {
client := getTestClient()
client.Expiration = time.Millisecond
keyName := "test_key"
value := "test_value"
client.Set(keyName, value)
time.Sleep(time.Millisecond * 2)
val, err := client.Get(keyName)
assert.Zero(t, val)
assert.NotNil(t, err)
}
func getTestClient() *caching.CacheClient {
client := new(caching.CacheClient)
client.Init()
return client
}