func TestGet(t *testing.T) { assert := assert.New(t) key := "key" pool := helper.TestGetPool() c := NewRedisCache(pool) c.SetPrefix(testRedisPrefix) // set data b := helper.TestGobItem("valueTestGet") _, err := pool.Get().Do("SETEX", testRedisPrefix+key, 300, b) assert.Nil(err) // get data var result string ok := c.Get(key, &result) assert.True(ok) assert.Equal("valueTestGet", result) // nil value b = helper.TestGobItem(nil) _, err = pool.Get().Do("SETEX", testRedisPrefix+key, 300, b) assert.Nil(err) var result2 string ok = c.Get(key, &result2) assert.False(ok) assert.Empty(result2) }
func TestGetInterface(t *testing.T) { assert := assert.New(t) key := "key" pool := helper.TestGetPool() c := NewRedisCache(pool) c.SetPrefix(testRedisPrefix) // set data b := helper.TestGobItem("valueTestGetInterface") _, err := pool.Get().Do("SETEX", testRedisPrefix+key, 300, b) assert.Nil(err) // get data v, ok := c.GetInterface(key) assert.True(ok) assert.Equal("valueTestGetInterface", v) }
func TestGetGobBytes(t *testing.T) { assert := assert.New(t) key := "key" pool := helper.TestGetPool() c := NewRedisCache(pool) c.SetPrefix(testRedisPrefix) // set data b := helper.TestGobItem("valueTestGetGobBytes") _, err := pool.Get().Do("SETEX", testRedisPrefix+key, 300, b) assert.Nil(err) // get data b, ok := c.GetGobBytes(key) assert.True(ok) var result string buf := bytes.NewBuffer(b) dec := gob.NewDecoder(buf) err = dec.Decode(&result) assert.Nil(err) assert.Equal("valueTestGetGobBytes", result) }