xredis

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 9 Imported by: 0

README

xredis

Dependencies

  • github.com/go-redis/redis
  • github.com/sirupsen/logrus

Documents

Types
  • type ILogger interface
  • type SilenceLogger struct
  • type LogrusLogger struct
  • type LoggerLogger struct
Variables
  • None
Constants
  • None
Functions
  • func DelAll(client *redis.Client, pattern string) (tot, del int, err error)
  • func SetAll(client *redis.Client, keys, values []string) (tot, add int, err error)
  • func SetExAll(client *redis.Client, keys, values []string, expirations []int64) (tot, add int, err error)
  • func NewSilenceLogger() *SilenceLogger
  • func NewLogrusLogger(logger *logrus.Logger) *LogrusLogger
  • func NewLoggerLogger(logger logrus.StdLogger) *LoggerLogger
Methods
  • func (l *SilenceLogger) Printf(context.Context, string, ...interface{})
  • func (l *LogrusLogger) AfterProcess(ctx context.Context, cmd redis.Cmder) error
  • func (l *LoggerLogger) AfterProcess(ctx context.Context, cmd redis.Cmder) error

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DelAll

func DelAll(client *redis.Client, pattern string) (tot, del int, err error)

DelAll deletes all keys from given pattern (KEYS -> DEL). This is an atomic operator and return err when failed.

func SetAll

func SetAll(client *redis.Client, keys, values []string) (tot, add int, err error)

SetAll sets all given key-value pairs (SET -> SET -> ...). This is a non-atomic operator, that means if there is a value failed to set, no rollback will be done, and it will return the current added count and error value.

func SetExAll

func SetExAll(client *redis.Client, keys, values []string, expirations []int64) (tot, add int, err error)

SetExAll sets all given key-value-expiration pairs (SET -> SET -> ...), equals to SetAll with expiration in second. This is a non-atomic operator, that means if there is a value failed to set, no rollback will be done, and it will return the current added count and error value.

Types

type ILogger

type ILogger interface {
	Printf(ctx context.Context, format string, v ...interface{})
}

ILogger represents neo4j's internal logger interface.

type LoggerLogger

type LoggerLogger struct {
	// contains filtered or unexported fields
}

LoggerLogger represents a redis's logger (as redis.Hook), used to log redis command executing message to logrus.StdLogger.

func NewLoggerLogger

func NewLoggerLogger(logger logrus.StdLogger) *LoggerLogger

NewLoggerLogger creates a new LoggerLogger using given logrus.StdLogger. Example:

client := redis.NewClient(options)
redis.SetLogger(NewSilenceLogger())
l := log.New(os.Stderr, "", log.LstdFlags)
client.AddHook(xredis.NewLoggerLogger(l))

func (*LoggerLogger) AfterProcess

func (l *LoggerLogger) AfterProcess(ctx context.Context, cmd redis.Cmder) error

AfterProcess logs to logrus.StdLogger.

func (*LoggerLogger) AfterProcessPipeline

func (l *LoggerLogger) AfterProcessPipeline(context.Context, []redis.Cmder) error

func (*LoggerLogger) BeforeProcess

func (l *LoggerLogger) BeforeProcess(ctx context.Context, _ redis.Cmder) (context.Context, error)

BeforeProcess saves start time to context, used in AfterProcess.

func (*LoggerLogger) BeforeProcessPipeline

func (l *LoggerLogger) BeforeProcessPipeline(ctx context.Context, _ []redis.Cmder) (context.Context, error)

type LogrusLogger

type LogrusLogger struct {
	// contains filtered or unexported fields
}

LogrusLogger represents a redis's logger (as redis.Hook), used to log redis command executing message to logrus.Logger.

func NewLogrusLogger

func NewLogrusLogger(logger *logrus.Logger) *LogrusLogger

NewLogrusLogger creates a new LogrusLogger using given logrus.Logger. Example:

client := redis.NewClient(options)
redis.SetLogger(NewSilenceLogger())
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 logs to logrus.Logger.

func (*LogrusLogger) AfterProcessPipeline

func (l *LogrusLogger) AfterProcessPipeline(context.Context, []redis.Cmder) error

func (*LogrusLogger) BeforeProcess

func (l *LogrusLogger) BeforeProcess(ctx context.Context, _ redis.Cmder) (context.Context, error)

BeforeProcess saves start time to context, used in AfterProcess.

func (*LogrusLogger) BeforeProcessPipeline

func (l *LogrusLogger) BeforeProcessPipeline(ctx context.Context, _ []redis.Cmder) (context.Context, error)

type SilenceLogger

type SilenceLogger struct{}

SilenceLogger represents a redis's logger, used to hide go-redis's info logger.

func NewSilenceLogger

func NewSilenceLogger() *SilenceLogger

NewSilenceLogger creates a new SilenceLogger. Example:

client := redis.NewClient(options)
redis.SetLogger(xredis.NewSilenceLogger())

func (*SilenceLogger) Printf

func (l *SilenceLogger) Printf(context.Context, string, ...interface{})

Printf does nothing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL