1 // Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
2 // Revel Framework source code and usage is governed by a MIT style
3 // license that can be found in the LICENSE file.
12 "github.com/revel/config"
13 "github.com/revel/revel"
16 // These tests require redis server running on localhost:6379 (the default)
17 const redisTestServer = "localhost:6379"
19 var newRedisCache = func(t *testing.T, defaultExpiration time.Duration) Cache {
20 revel.Config = config.NewContext()
22 c, err := net.Dial("tcp", redisTestServer)
24 if _, err = c.Write([]byte("flush_all\r\n")); err != nil {
25 t.Errorf("Write failed: %s", err)
29 redisCache := NewRedisCache(redisTestServer, "", defaultExpiration)
30 if err = redisCache.Flush(); err != nil {
31 t.Errorf("Flush failed: %s", err)
35 t.Errorf("couldn't connect to redis on %s", redisTestServer)
40 func TestRedisCache_TypicalGetSet(t *testing.T) {
41 typicalGetSet(t, newRedisCache)
44 func TestRedisCache_IncrDecr(t *testing.T) {
45 incrDecr(t, newRedisCache)
48 func TestRedisCache_Expiration(t *testing.T) {
49 expiration(t, newRedisCache)
52 func TestRedisCache_EmptyCache(t *testing.T) {
53 emptyCache(t, newRedisCache)
56 func TestRedisCache_Replace(t *testing.T) {
57 testReplace(t, newRedisCache)
60 func TestRedisCache_Add(t *testing.T) {
61 testAdd(t, newRedisCache)
64 func TestRedisCache_GetMulti(t *testing.T) {
65 testGetMulti(t, newRedisCache)