Documentation ¶
Index ¶
- Constants
- Variables
- func DelAll(ctx context.Context, client *redis.Client, pattern string) (tot int64, err error)
- func DelAllByScan(ctx context.Context, client *redis.Client, pattern string, scanCount int64) (tot int64, err error)
- func DelAllByScanCallback(ctx context.Context, client *redis.Client, pattern string, scanCount int64, ...) (tot int64, err error)
- func DisableLogger()
- func EnableLogger()
- func ScanAll(ctx context.Context, client *redis.Client, match string, count int64) (keys []string, err error)
- func ScanAllWithCallback(ctx context.Context, client *redis.Client, match string, count int64, ...) error
- type ILogger
- type LoggerOption
- type LoggerParam
- type LogrusLogger
- func (l *LogrusLogger) AfterProcess(ctx context.Context, cmd redis.Cmder) error
- func (*LogrusLogger) AfterProcessPipeline(context.Context, []redis.Cmder) error
- func (l *LogrusLogger) BeforeProcess(ctx context.Context, _ redis.Cmder) (context.Context, error)
- func (*LogrusLogger) BeforeProcessPipeline(ctx context.Context, _ []redis.Cmder) (context.Context, error)
- type SilenceLogger
- type StdLogger
- func (l *StdLogger) AfterProcess(ctx context.Context, cmd redis.Cmder) error
- func (*StdLogger) AfterProcessPipeline(context.Context, []redis.Cmder) error
- func (l *StdLogger) BeforeProcess(ctx context.Context, _ redis.Cmder) (context.Context, error)
- func (*StdLogger) BeforeProcessPipeline(ctx context.Context, _ []redis.Cmder) (context.Context, error)
Constants ¶
const ( // NAME represents ahlib-mx/xredis package's name. NAME = "ahlib-mx/xredis" // VERSION represents ahlib-mx/xredis package's current version. VERSION = "1.6.0" )
Variables ¶
var ( // FormatLoggerFunc is a custom LoggerParam's format function for LogrusLogger and StdLogger. FormatLoggerFunc func(p *LoggerParam) string // FieldifyLoggerFunc is a custom LoggerParam's fieldify function for LogrusLogger. FieldifyLoggerFunc func(p *LoggerParam) logrus.Fields )
Functions ¶
func DelAll ¶
DelAll atomically deletes all keys from given pattern, using KEYS command to get all keys before DEL command.
func DelAllByScan ¶
func DelAllByScan(ctx context.Context, client *redis.Client, pattern string, scanCount int64) (tot int64, err error)
DelAllByScan atomically deletes all keys from given pattern, using SCAN command to get all keys before DEL command.
func DelAllByScanCallback ¶
func DelAllByScanCallback(ctx context.Context, client *redis.Client, pattern string, scanCount int64, ignoreDelError bool) (tot int64, err error)
DelAllByScanCallback atomically deletes all keys from given pattern, using SCAN command with callback and DEL command multi times.
func EnableLogger ¶
func EnableLogger()
EnableLogger enables LogrusLogger and StdLogger to do any log.
func ScanAll ¶
func ScanAll(ctx context.Context, client *redis.Client, match string, count int64) (keys []string, err error)
ScanAll scans all keys from given pattern and scan count, and returns all keys when finish scanning, is a wrapper function for SCAN command.
func ScanAllWithCallback ¶
func ScanAllWithCallback(ctx context.Context, client *redis.Client, match string, count int64, callback func(keys []string, cursor uint64) (toContinue bool)) error
ScanAllWithCallback scans all keys from given pattern and scan count, and invokes callback when get some keys, is a wrapper function for SCAN command.
Types ¶
type LoggerOption ¶
type LoggerOption func(*loggerOptions)
LoggerOption represents an option type for LogrusLogger and StdLogger's option, can be created by WithXXX functions.
func WithLogCmd ¶
func WithLogCmd(log bool) LoggerOption
WithLogCmd creates a LoggerOption to decide whether to do log for redis commands or not, defaults to true.
func WithLogErr ¶
func WithLogErr(log bool) LoggerOption
WithLogErr creates a LoggerOption to decide whether to do log for errors or not, defaults to true.
func WithSkip ¶
func WithSkip(skip int) LoggerOption
WithSkip creates a LoggerOption to specify runtime skip for getting runtime information, defaults to 4.
func WithSlowThreshold ¶
func WithSlowThreshold(threshold time.Duration) LoggerOption
WithSlowThreshold creates a LoggerOption to specify a slow operation's duration used to highlight loggers, defaults to 0ms, means no highlight.
type LoggerParam ¶
type LoggerParam struct { Command string Rows int64 Status string Duration time.Duration Slow bool Source string ErrorMsg string }
LoggerParam stores some logger parameters and is used by LogrusLogger and StdLogger.
type LogrusLogger ¶
type LogrusLogger struct {
// contains filtered or unexported fields
}
LogrusLogger represents a redis.Hook as redis's logger, used to log redis's executing message to logrus.Logger.
func NewLogrusLogger ¶
func NewLogrusLogger(logger *logrus.Logger, options ...LoggerOption) *LogrusLogger
NewLogrusLogger creates a new LogrusLogger using given logrus.Logger and LoggerOption-s.
Example:
client := redis.NewClient(...) redis.SetLogger(NewSilenceLogger()) // must silence fist l := logrus.New() l.SetFormatter(&logrus.TextFormatter{}) client.AddHook(xredis.NewLogrusLogger(l))
func (*LogrusLogger) AfterProcess ¶
func (l *LogrusLogger) AfterProcess(ctx context.Context, cmd redis.Cmder) error
AfterProcess implements redis.Hook interface, it logs redis's message to logrus.Logger.
func (*LogrusLogger) AfterProcessPipeline ¶
func (*LogrusLogger) AfterProcessPipeline(context.Context, []redis.Cmder) error
AfterProcessPipeline implements redis.Hook interface.
func (*LogrusLogger) BeforeProcess ¶
BeforeProcess implements redis.Hook interface, it saves start time to context, and will be used in AfterProcess.
func (*LogrusLogger) BeforeProcessPipeline ¶
func (*LogrusLogger) BeforeProcessPipeline(ctx context.Context, _ []redis.Cmder) (context.Context, error)
BeforeProcessPipeline implements redis.Hook interface.
type SilenceLogger ¶
type SilenceLogger struct{}
SilenceLogger represents a redis's logger, used to hide all logs, including error message.
func NewSilenceLogger ¶
func NewSilenceLogger() *SilenceLogger
NewSilenceLogger creates a new SilenceLogger.
Example:
client := redis.NewClient(options) redis.SetLogger(xredis.NewSilenceLogger())
type StdLogger ¶
type StdLogger struct {
// contains filtered or unexported fields
}
StdLogger represents a redis.Hook as redis's logger, used to log redis's executing message to logrus.StdLogger.
func NewStdLogger ¶
func NewStdLogger(logger logrus.StdLogger, options ...LoggerOption) *StdLogger
NewStdLogger creates a new StdLogger using given logrus.StdLogger and LoggerOption-s.
Example:
client := redis.NewClient(...) redis.SetLogger(NewSilenceLogger()) // must silence fist l := log.Default() client.AddHook(xredis.NewStdLogger(l))
func (*StdLogger) AfterProcess ¶
AfterProcess implements redis.Hook interface, it logs redis's message to logrus.StdLogger.
func (*StdLogger) AfterProcessPipeline ¶
AfterProcessPipeline implements redis.Hook interface.
func (*StdLogger) BeforeProcess ¶
BeforeProcess implements redis.Hook interface, it saves start time to context, and will be used in AfterProcess.