mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
refract package ghttp/gredis/glog
This commit is contained in:
@ -679,9 +679,9 @@ func (c *Core) writeSqlToLogger(ctx context.Context, sql *Sql) {
|
||||
s := fmt.Sprintf("[%3d ms] [%s] %s%s", sql.End-sql.Start, sql.Group, transactionIdStr, sql.Format)
|
||||
if sql.Error != nil {
|
||||
s += "\nError: " + sql.Error.Error()
|
||||
c.logger.Ctx(ctx).Error(s)
|
||||
c.logger.Error(ctx, s)
|
||||
} else {
|
||||
c.logger.Ctx(ctx).Debug(s)
|
||||
c.logger.Debug(ctx, s)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,9 +17,6 @@ type Adapter interface {
|
||||
// Note that you should call Close function manually if you do not use this connection any further.
|
||||
Conn(ctx context.Context) (conn Conn, err error)
|
||||
|
||||
// Config returns the configuration that used in current redis object.
|
||||
Config(ctx context.Context) (config *Config, err error)
|
||||
|
||||
// Close closes current redis client, closes its connection pool and releases all its related resources.
|
||||
Close(ctx context.Context) (err error)
|
||||
}
|
||||
|
||||
@ -50,11 +50,6 @@ func NewAdapterGoRedis(config *Config) *AdapterGoRedis {
|
||||
}
|
||||
}
|
||||
|
||||
// Config returns the configuration that used in current redis object.
|
||||
func (r *AdapterGoRedis) Config(ctx context.Context) (config *Config, err error) {
|
||||
return r.config, nil
|
||||
}
|
||||
|
||||
// Close closes the redis connection pool, which will release all connections reserved by this pool.
|
||||
// It is commonly not necessary to call Close manually.
|
||||
func (r *AdapterGoRedis) Close(ctx context.Context) error {
|
||||
|
||||
@ -22,7 +22,6 @@ type localAdapterGoRedisConn struct {
|
||||
// Do sends a command to the server and returns the received reply.
|
||||
// It uses json.Marshal for struct/slice/map type values before committing them to redis.
|
||||
func (c *localAdapterGoRedisConn) Do(ctx context.Context, command string, args ...interface{}) (reply *gvar.Var, err error) {
|
||||
|
||||
switch gstr.ToLower(command) {
|
||||
case `subscribe`:
|
||||
c.ps = c.redis.client.Subscribe(ctx, gconv.Strings(args)...)
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package gredis
|
||||
|
||||
import "github.com/go-redis/redis/v8"
|
||||
|
||||
// localAdapterGoRedisPoolStats is statistics of redis connection pool.
|
||||
type localAdapterGoRedisPoolStats struct {
|
||||
*redis.PoolStats
|
||||
}
|
||||
|
||||
// ActiveCount is the number of connections in the pool. The count includes
|
||||
// idle connections and connections in use.
|
||||
func (s *localAdapterGoRedisPoolStats) ActiveCount() int64 {
|
||||
if s == nil {
|
||||
return -1
|
||||
}
|
||||
return int64(s.PoolStats.TotalConns)
|
||||
}
|
||||
|
||||
// IdleCount is the number of idle connections in the pool.
|
||||
func (s *localAdapterGoRedisPoolStats) IdleCount() int64 {
|
||||
if s == nil {
|
||||
return -1
|
||||
}
|
||||
return int64(s.PoolStats.IdleConns)
|
||||
}
|
||||
@ -56,10 +56,10 @@ func (c *RedisConn) addTracingItem(ctx context.Context, item *tracingItem) {
|
||||
|
||||
span.SetAttributes(gtrace.CommonLabels()...)
|
||||
|
||||
if config, _ := c.redis.adapter.Config(ctx); config == nil {
|
||||
if adapter, ok := c.redis.GetAdapter().(*AdapterGoRedis); ok {
|
||||
span.SetAttributes(
|
||||
attribute.String(tracingAttrRedisAddress, config.Address),
|
||||
attribute.Int(tracingAttrRedisDb, config.Db),
|
||||
attribute.String(tracingAttrRedisAddress, adapter.config.Address),
|
||||
attribute.Int(tracingAttrRedisDb, adapter.config.Db),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user