From e43357164c7b3e1b5c78f7d36bba72a51dde3ba6 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Wed, 29 Sep 2021 23:01:10 +0800 Subject: [PATCH] chore: replace redis.NewRedis with redis.New (#1103) --- core/limit/tokenlimit_test.go | 2 +- core/stores/cache/cachenode_test.go | 2 +- core/stores/mongoc/cachedcollection_test.go | 2 +- core/stores/redis/redis_test.go | 6 +++--- core/stores/redis/redisblockingnode_test.go | 4 ++-- core/stores/redis/redistest/redistest.go | 2 +- core/stores/sqlc/cachedsql_test.go | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/limit/tokenlimit_test.go b/core/limit/tokenlimit_test.go index ea15742a..e3b7bb35 100644 --- a/core/limit/tokenlimit_test.go +++ b/core/limit/tokenlimit_test.go @@ -24,7 +24,7 @@ func TestTokenLimit_Rescue(t *testing.T) { rate = 5 burst = 10 ) - l := NewTokenLimiter(rate, burst, redis.NewRedis(s.Addr(), redis.NodeType), "tokenlimit") + l := NewTokenLimiter(rate, burst, redis.New(s.Addr()), "tokenlimit") s.Close() var allowed int diff --git a/core/stores/cache/cachenode_test.go b/core/stores/cache/cachenode_test.go index 2e3dd6a9..1e954c8f 100644 --- a/core/stores/cache/cachenode_test.go +++ b/core/stores/cache/cachenode_test.go @@ -73,7 +73,7 @@ func TestCacheNode_InvalidCache(t *testing.T) { defer s.Close() cn := cacheNode{ - rds: redis.NewRedis(s.Addr(), redis.NodeType), + rds: redis.New(s.Addr()), r: rand.New(rand.NewSource(time.Now().UnixNano())), lock: new(sync.Mutex), unstableExpiry: mathx.NewUnstable(expiryDeviation), diff --git a/core/stores/mongoc/cachedcollection_test.go b/core/stores/mongoc/cachedcollection_test.go index a1337cb7..f2363569 100644 --- a/core/stores/mongoc/cachedcollection_test.go +++ b/core/stores/mongoc/cachedcollection_test.go @@ -120,7 +120,7 @@ func TestStatCacheFails(t *testing.T) { log.SetOutput(ioutil.Discard) defer log.SetOutput(os.Stdout) - r := redis.NewRedis("localhost:59999", redis.NodeType) + r := redis.New("localhost:59999") cach := cache.NewNode(r, sharedCalls, stats, mgo.ErrNotFound) c := newCollection(dummyConn{}, cach) diff --git a/core/stores/redis/redis_test.go b/core/stores/redis/redis_test.go index 2416fffc..37e60ec4 100644 --- a/core/stores/redis/redis_test.go +++ b/core/stores/redis/redis_test.go @@ -963,7 +963,7 @@ func TestRedis_Pipelined(t *testing.T) { func TestRedisString(t *testing.T) { runOnRedis(t, func(client *Redis) { client.Ping() - _, err := getRedis(NewRedis(client.Addr, ClusterType)) + _, err := getRedis(New(client.Addr, Cluster())) assert.Nil(t, err) assert.Equal(t, client.Addr, client.String()) assert.NotNil(t, New(client.Addr, badType()).Ping()) @@ -1075,7 +1075,7 @@ func TestRedisGeo(t *testing.T) { func TestRedis_WithPass(t *testing.T) { runOnRedis(t, func(client *Redis) { - err := NewRedis(client.Addr, NodeType, "any").Ping() + err := New(client.Addr, WithPass("any")).Ping() assert.NotNil(t, err) }) } @@ -1095,7 +1095,7 @@ func runOnRedis(t *testing.T, fn func(client *Redis)) { client.Close() } }() - fn(NewRedis(s.Addr(), NodeType)) + fn(New(s.Addr())) } func runOnRedisTLS(t *testing.T, fn func(client *Redis)) { diff --git a/core/stores/redis/redisblockingnode_test.go b/core/stores/redis/redisblockingnode_test.go index b64a887b..80ac70ce 100644 --- a/core/stores/redis/redisblockingnode_test.go +++ b/core/stores/redis/redisblockingnode_test.go @@ -10,10 +10,10 @@ import ( func TestBlockingNode(t *testing.T) { r, err := miniredis.Run() assert.Nil(t, err) - node, err := CreateBlockingNode(NewRedis(r.Addr(), NodeType)) + node, err := CreateBlockingNode(New(r.Addr())) assert.Nil(t, err) node.Close() - node, err = CreateBlockingNode(NewRedis(r.Addr(), ClusterType)) + node, err = CreateBlockingNode(New(r.Addr(), Cluster())) assert.Nil(t, err) node.Close() } diff --git a/core/stores/redis/redistest/redistest.go b/core/stores/redis/redistest/redistest.go index adebcb3b..09f5223f 100644 --- a/core/stores/redis/redistest/redistest.go +++ b/core/stores/redis/redistest/redistest.go @@ -15,7 +15,7 @@ func CreateRedis() (r *redis.Redis, clean func(), err error) { return nil, nil, err } - return redis.NewRedis(mr.Addr(), redis.NodeType), func() { + return redis.New(mr.Addr()), func() { ch := make(chan lang.PlaceholderType) go func() { mr.Close() diff --git a/core/stores/sqlc/cachedsql_test.go b/core/stores/sqlc/cachedsql_test.go index 5afffe05..5f325306 100644 --- a/core/stores/sqlc/cachedsql_test.go +++ b/core/stores/sqlc/cachedsql_test.go @@ -286,7 +286,7 @@ func TestStatCacheFails(t *testing.T) { log.SetOutput(ioutil.Discard) defer log.SetOutput(os.Stdout) - r := redis.NewRedis("localhost:59999", redis.NodeType) + r := redis.New("localhost:59999") c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10)) for i := 0; i < 20; i++ { @@ -485,7 +485,7 @@ func TestCachedConnExecDropCache(t *testing.T) { value = "any" ) var conn trackedConn - c := NewNodeConn(&conn, redis.NewRedis(r.Addr(), redis.NodeType), cache.WithExpiry(time.Second*30)) + c := NewNodeConn(&conn, redis.New(r.Addr()), cache.WithExpiry(time.Second*30)) assert.Nil(t, c.SetCache(key, value)) _, err = c.Exec(func(conn sqlx.SqlConn) (result sql.Result, e error) { return conn.Exec("delete from user_table where id='kevin'") @@ -503,7 +503,7 @@ func TestCachedConnExecDropCache(t *testing.T) { func TestCachedConnExecDropCacheFailed(t *testing.T) { const key = "user" var conn trackedConn - r := redis.NewRedis("anyredis:8888", redis.NodeType) + r := redis.New("anyredis:8888") c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*10)) _, err := c.Exec(func(conn sqlx.SqlConn) (result sql.Result, e error) { return conn.Exec("delete from user_table where id='kevin'")