Skip to content

Commit

Permalink
完善redis中test代码。
Browse files Browse the repository at this point in the history
  • Loading branch information
DyncMing committed Nov 17, 2022
1 parent c3cf2ef commit d67f309
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 51 deletions.
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ type RedisConfig struct {
//最大连接数
DBMaxActive int `yaml:"dbMaxActive"`
//redis表示空闲连接保活时间
DBIdleTimeout int `yaml:"DBIdleTimeout"`
DBIdleTimeout int `yaml:"dbIdleTimeout"`
//redis用户
DBUserName string `yaml:"dbUserName"`
//redis密码
DBPassWord string `yaml:"dbPassWord"`
//是否使用redis集群
Expand Down
2 changes: 1 addition & 1 deletion service/redis_cache_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type RedisCacheService struct {

// NewConfigRedisCacheService 初始化自定义redis配置
func NewConfigRedisCacheService(rdsAddr []string, dbUserName, dbPassword string, enableCluster bool, db int) CaptchaCacheInterface {
redisUtils := util.NewConfigRedisUtil(rdsAddr, dbPassword, enableCluster, db)
redisUtils := util.NewConfigRedisUtil(rdsAddr, dbUserName, dbPassword, enableCluster, db)
return &RedisCacheService{Cache: redisUtils}
}

Expand Down
52 changes: 3 additions & 49 deletions test/redis_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,8 @@ import (
"time"
)

func TestDftRedisUtil_Delete(t *testing.T) {
cache := util.NewDftRedisUtil()
val := "testval"
key := "testdft"
cache.Set(key, val, 10)
cache.Delete(key)

if cache.Get(key) != "" {
t.Fatal("default 缓存删除值失败")
}
}

func TestConfigRedisUtil_Delete(t *testing.T) {
cache := util.NewConfigRedisUtil([]string{"192.168.1.111:6379"}, "", false, 0)
cache := util.NewConfigRedisUtil([]string{"192.168.1.111:6379"}, "", "", false, 0)
val := "testvalconfig"
key := "testconfig"
cache.Set(key, val, 10)
Expand All @@ -30,25 +18,8 @@ func TestConfigRedisUtil_Delete(t *testing.T) {
}
}

func TestDftRedisUtil_Exists(t *testing.T) {
cache := util.NewDftRedisUtil()
val := "testvaldft"
key := "testdft"
key1 := "test1dft"
cache.Set(key, val, 10)
cache.Set(key1, val, 0)

if cache.Exists(key) != true {
t.Fatal("default Exists 获取的值不符合要求")
}

if cache.Exists(key1) != true {
t.Fatal("default Exists 获取的值不符合要求")
}
}

func TestConfigRedisUtil_Exists(t *testing.T) {
cache := util.NewConfigRedisUtil([]string{"192.168.1.111:6379"}, "", false, 0)
cache := util.NewConfigRedisUtil([]string{"192.168.1.111:6379"}, "", "", false, 0)
val := "testvalconfig"
key := "testconfig"
key1 := "test1config"
Expand All @@ -64,25 +35,8 @@ func TestConfigRedisUtil_Exists(t *testing.T) {
}
}

func TestDftRedisUtil_Get(t *testing.T) {
cache := util.NewDftRedisUtil()
val := "testvaldft"
key := "testdft"
cache.Set(key, val, 10)

if cache.Get(key) != val {
t.Fatal("default 获取的值不符合要求")
}

time.Sleep(time.Duration(11) * time.Second)

if cache.Get(key) != "" {
t.Fatal("default 时间失效失败")
}
}

func TestConfigRedisUtil_Get(t *testing.T) {
cache := util.NewConfigRedisUtil([]string{"192.168.1.111:6379"}, "", false, 0)
cache := util.NewConfigRedisUtil([]string{"192.168.1.111:6379"}, "", "", false, 0)
val := "testvalconfig"
key := "testconfig"
cache.Set(key, val, 10)
Expand Down

0 comments on commit d67f309

Please sign in to comment.