Skip to content

Commit

Permalink
feat: redisgo rename to redis (#518)
Browse files Browse the repository at this point in the history
Co-authored-by: papa-hexuan <[email protected]>
  • Loading branch information
papa-hexuan and papa-hexuan authored Oct 26, 2022
1 parent f0f1f7b commit e665921
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions pkg/client/redisgo/client.go → pkg/client/redis/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redisgo
package redis

import (
"context"
Expand All @@ -21,13 +21,13 @@ type Client struct {

func (ins *Client) CmdOnMaster() *redis.Client {
if ins.master == nil {
ins.config.logger.Panic("redisgo:no master for "+ins.config.name, xlog.FieldExtMessage(ins.config))
ins.config.logger.Panic("redis:no master for "+ins.config.name, xlog.FieldExtMessage(ins.config))
}
return ins.master
}
func (ins *Client) CmdOnSlave() *redis.Client {
if len(ins.slave) == 0 {
ins.config.logger.Panic("redisgo:no slave for "+ins.config.name, xlog.FieldExtMessage(ins.config))
ins.config.logger.Panic("redis:no slave for "+ins.config.name, xlog.FieldExtMessage(ins.config))
}
return ins.slave[rand.Intn(len(ins.slave))]
}
Expand All @@ -54,7 +54,7 @@ func (config *Config) MustSingleton() *Client {

cc, err := config.Build()
if err != nil {
config.logger.Panic("redisgo:"+err.Error(), xlog.FieldExtMessage(config))
config.logger.Panic("redis:"+err.Error(), xlog.FieldExtMessage(config))
}
singleton.Store(constant.ModuleClientRedis, config.name, cc)
return cc
Expand All @@ -65,7 +65,7 @@ func (config *Config) Build() (*Client, error) {
ins := new(Client)
var err error
if xdebug.IsDevelopmentMode() {
xdebug.PrettyJsonPrint("redisgo's config: "+config.name, config)
xdebug.PrettyJsonPrint("redis's config: "+config.name, config)
}
if config.Master.Addr != "" {
addr, user, pass := getUsernameAndPassword(config.Master.Addr)
Expand Down Expand Up @@ -123,9 +123,9 @@ func (config *Config) build(addr, user, pass string) (*redis.Client, error) {

if err := stubClient.Ping(context.Background()).Err(); err != nil {
if config.OnDialError == "panic" {
config.logger.Panic("redisgo stub client start err: " + err.Error())
config.logger.Panic("redis stub client start err: " + err.Error())
}
config.logger.Error("redisgo stub client start err", xlog.FieldErr(err))
config.logger.Error("redis stub client start err", xlog.FieldErr(err))
return nil, err
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redisgo
package redis

import (
"context"
Expand All @@ -16,7 +16,7 @@ func Test_Stub(t *testing.T) {
var client *Client
defer func() {
if r := recover(); r != nil {
assert.Equal(t, r.(string), "redisgo:no master or slaves for default")
assert.Equal(t, r.(string), "redis:no master or slaves for default")
assert.Nil(t, client)
}
}()
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/redisgo/config.go → pkg/client/redis/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redisgo
package redis

import (
"strings"
Expand Down Expand Up @@ -95,7 +95,7 @@ func DefaultConfig() *Config {

// StdConfig ...
func StdConfig(name string) *Config {
return RawConfig(name, constant.ConfigKey("redisgo", name, "stub"))
return RawConfig(name, constant.ConfigKey("redis", name, "stub"))
}
func RawConfig(name, key string) *Config {
var config = DefaultConfig()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redisgo
package redis

import (
"bytes"
Expand All @@ -13,18 +13,18 @@ import (
)

func TestStdConfig(t *testing.T) {
assert.Equal(t, constant.ConfigKey("redisgo", "test", "stub"), "jupiter.redisgo.test.stub")
assert.Equal(t, constant.ConfigKey("redis", "test", "stub"), "jupiter.redis.test.stub")

var configStr = `
[jupiter.redisgo]
[jupiter.redisgo.test.stub]
[jupiter.redis]
[jupiter.redis.test.stub]
dialTimeout="2s"
readTimeout="5s"
idleTimeout="60s"
username=""
password="123"
[jupiter.redisgo.test.cluster]
[jupiter.redis.test.cluster]
dialTimeout="2s"
readTimeout="5s"
idleTimeout="60s"
Expand All @@ -46,15 +46,15 @@ func TestStdConfig(t *testing.T) {

func TestConfig(t *testing.T) {
var configStr = `
[jupiter.redisgo]
[jupiter.redisgo.test]
[jupiter.redisgo.test.stub]
[jupiter.redis]
[jupiter.redis.test]
[jupiter.redis.test.stub]
dialTimeout="2s"
readTimeout="5s"
idleTimeout="60s"
[jupiter.redisgo.test.stub.master]
[jupiter.redis.test.stub.master]
addr="redis://:user111:[email protected]:6379"
[jupiter.redisgo.test.stub.slaves]
[jupiter.redis.test.stub.slaves]
addr=[
"redis://:user111:[email protected]:6379",
]
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/redisgo/init.go → pkg/client/redis/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redisgo
package redis

import (
"net/http"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redisgo
package redis

import (
"context"
Expand Down Expand Up @@ -125,7 +125,7 @@ func debugInterceptor(compName string, addr string, config *Config, logger *xlog
cost := time.Since(ctx.Value(ctxBegKey).(time.Time))
err := cmd.Err()
fmt.Println(xstring.CallerName(6))
fmt.Printf("[redisgo ] %s (%s) :\n", addr, cost) // nolint
fmt.Printf("[redis ] %s (%s) :\n", addr, cost) // nolint
if err != nil {
fmt.Printf(color.RedString("# %s %+v, ERR=(%s)\n\n", cmd.Name(), cmd.Args(), err.Error())) // nolint
} else {
Expand All @@ -136,7 +136,7 @@ func debugInterceptor(compName string, addr string, config *Config, logger *xlog
setAfterProcessPipeline(func(ctx context.Context, cmds []redis.Cmder) error {
cost := time.Since(ctx.Value(ctxBegKey).(time.Time))
fmt.Println(xstring.CallerName(8))
fmt.Printf("[redisgo pipeline] %s (%s) :\n", addr, cost) // nolint
fmt.Printf("[redis pipeline] %s (%s) :\n", addr, cost) // nolint
for _, cmd := range cmds {
err := cmd.Err()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redisgo
package redis

import (
"context"
Expand Down

0 comments on commit e665921

Please sign in to comment.