Skip to content

Commit

Permalink
fix redis logger level and replace jsoniter
Browse files Browse the repository at this point in the history
  • Loading branch information
sevennt committed Nov 9, 2023
1 parent c3d0ac4 commit 99b0db1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,5 @@ func (c *Container) buildStub() *redis.Client {
}

func (c *Container) Printf(ctx context.Context, format string, v ...interface{}) {
c.logger.Errorf(format, v...)
c.logger.Infof(format, v...)
}
8 changes: 4 additions & 4 deletions examples/redis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func invokerRedis() error {
func testRedis() error {
err := eredisClient.Set(context.Background(), "hello", "world", 0)
fmt.Println("set hello", err)
//str, err := eredisClient.Get(context.Background(), "hello")
//fmt.Println("get hello", str, err)
//str, err = eredisClient.Get(context.Background(), "lee")
//fmt.Println("Get lee", errors.Is(err, eredis.Nil), "err="+err.Error())
// str, err := eredisClient.Get(context.Background(), "hello")
// fmt.Println("get hello", str, err)
// str, err = eredisClient.Get(context.Background(), "lee")
// fmt.Println("Get lee", errors.Is(err, eredis.Nil), "err="+err.Error())
eredisClient.Get(context.Background(), "hello")
eredisClient.Get(context.Background(), "lee")
return nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/go-redis/redis/extra/rediscmd/v8 v8.11.4
github.com/go-redis/redis/v8 v8.11.4
github.com/gotomicro/ego v1.0.3
github.com/json-iterator/go v1.1.12
github.com/spf13/cast v1.3.1
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel v1.4.1
Expand All @@ -30,6 +29,7 @@ require (
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/gotomicro/logrotate v0.0.0-20211108024517-45d1f9a03ff5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.3.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand Down
7 changes: 5 additions & 2 deletions stat.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package eredis

import (
"encoding/json"
"net/http"
"sync"
"time"

"github.com/go-redis/redis/v8"
"github.com/gotomicro/ego/core/elog"
"github.com/gotomicro/ego/core/emetric"
"github.com/gotomicro/ego/server/egovernor"
jsoniter "github.com/json-iterator/go"
)

var instances = sync.Map{}
Expand All @@ -20,7 +21,9 @@ type storeRedis struct {

func init() {
egovernor.HandleFunc("/debug/redis/stats", func(w http.ResponseWriter, r *http.Request) {
_ = jsoniter.NewEncoder(w).Encode(stats())
if err := json.NewEncoder(w).Encode(stats()); err != nil {
elog.Error("encode stats fail", elog.FieldErr(err))
}
})
go monitor()
}
Expand Down

0 comments on commit 99b0db1

Please sign in to comment.