Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

internal

v9.24.1
github.com/redis/go-redis/v9/internal

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

53 matches

Top ↑

Constants

DefaultLoggerCalldepth (2 declarations)

const (
	DefaultLoggerCalldepth = 3
	FilterLoggerCalldepth  = 4
)

Calldepth values for NewDefaultLogger. Reads through Logger.Printf add one forwarding frame (atomicLogger.Printf), so the plain default logger uses DefaultLoggerCalldepth; wrappers that add another Printf frame (e.g. logging's filterLogger) use FilterLoggerCalldepth.

NaN (3 declarations)

const (
	NaN  = "nan"  // Not a Number
	Inf  = "inf"  // Positive infinity
	NInf = "-inf" // Negative infinity
)

String representations of special float values. Values are lowercase for consistency with Redis RESP2 protocol responses.

RedisNull

const RedisNull = "<nil>"

Variables

LogLevel

var LogLevel = newAtomicLogLevel(LogLevelError)

Logger

var Logger = newAtomicLogger(NewDefaultLogger(DefaultLoggerCalldepth))

Logger calls Output to print to the stderr. Arguments are handled in the manner of fmt.Print. Swap it with redis.SetLogger; read it through Logger.Printf.

Functions

AppendArg

func AppendArg(b []byte, v interface{}) []byte

FormatFloat

func FormatFloat(f float64) string

FormatFloat formats a float64 to string, normalizing special values (NaN, Inf) to lowercase for consistency with Redis RESP2 protocol.

GetAddr

func GetAddr(addr string) string

ReplaceSpaces

func ReplaceSpaces(s string) string

RetryBackoff

func RetryBackoff(retry int, minBackoff, maxBackoff time.Duration) time.Duration

Sleep

func Sleep(ctx context.Context, dur time.Duration) error

ToFloat

func ToFloat(val interface{}) float64

ToInteger

func ToInteger(val interface{}) int

ToLower

func ToLower(s string) string

ToString

func ToString(val interface{}) string

ToStringSlice

func ToStringSlice(val interface{}) []string

Types

DefaultLogger

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

DefaultLogger.Printf

func (l *DefaultLogger) Printf(ctx context.Context, format string, v ...interface{})

FIFOSemaphore

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

FIFOSemaphore is a channel-based semaphore with strict FIFO ordering. Unlike FastSemaphore, this guarantees that threads are served in the exact order they call Acquire(). The channel is pre-filled with tokens: Acquire = receive, Release = send. Closing the semaphore unblocks all waiting goroutines.

Performance: ~115 ns/op with zero allocations (slower than FastSemaphore due to timer allocation). Fairness: Strict FIFO ordering guaranteed by Go runtime.

NewFIFOSemaphore

func NewFIFOSemaphore(capacity int32) *FIFOSemaphore

NewFIFOSemaphore creates a new FIFO semaphore with the given capacity.

FIFOSemaphore.Acquire

func (s *FIFOSemaphore) Acquire(ctx context.Context, timeout time.Duration, timeoutErr error) error

Acquire acquires a token, blocking if necessary until one is available. Returns an error if the context is cancelled or the timeout expires. Always uses timer to guarantee FIFO ordering (no fast path).

FIFOSemaphore.Release

func (s *FIFOSemaphore) Release()

Release releases a token back to the semaphore.

FIFOSemaphore.TryAcquire

func (s *FIFOSemaphore) TryAcquire() bool

TryAcquire attempts to acquire a token without blocking. Returns true if successful, false if no tokens available.

FastSemaphore

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

FastSemaphore is a channel-based semaphore optimized for performance. It uses a fast path that avoids timer allocation when tokens are available. The channel is pre-filled with tokens: Acquire = receive, Release = send. Closing the semaphore unblocks all waiting goroutines.

Performance: ~30 ns/op with zero allocations on fast path. Fairness: Eventual fairness (no starvation) but not strict FIFO.

NewFastSemaphore

func NewFastSemaphore(capacity int32) *FastSemaphore

NewFastSemaphore creates a new fast semaphore with the given capacity.

FastSemaphore.Acquire

func (s *FastSemaphore) Acquire(ctx context.Context, timeout time.Duration, timeoutErr error) error

Acquire acquires a token, blocking if necessary until one is available. Returns an error if the context is cancelled or the timeout expires. Uses a fast path to avoid timer allocation when tokens are immediately available.

FastSemaphore.AcquireBlocking

func (s *FastSemaphore) AcquireBlocking()

AcquireBlocking acquires a token, blocking indefinitely until one is available.

FastSemaphore.Available

func (s *FastSemaphore) Available() int

Available returns the number of tokens currently free (an approximation under concurrency). Zero means every turn is taken — by an in-use connection or an in-flight dial — so the next Acquire would block. Used as a non-blocking capacity probe; not a synchronization primitive.

FastSemaphore.Close

func (s *FastSemaphore) Close()

Close closes the semaphore, unblocking all waiting goroutines. After close, all Acquire calls will receive a closed channel signal.

FastSemaphore.Len

func (s *FastSemaphore) Len() int32

Len returns the current number of acquired tokens.

FastSemaphore.Release

func (s *FastSemaphore) Release()

Release releases a token back to the semaphore.

FastSemaphore.TryAcquire

func (s *FastSemaphore) TryAcquire() bool

TryAcquire attempts to acquire a token without blocking. Returns true if successful, false if no tokens available.

LogLevelT

type LogLevelT int

LogLevelT represents the logging level

LogLevelError (4 declarations)

const (
	LogLevelError LogLevelT = iota // 0 - errors only
	LogLevelWarn                   // 1 - warnings and errors
	LogLevelInfo                   // 2 - info, warnings, and errors
	LogLevelDebug                  // 3 - debug, info, warnings, and errors
)

Log level constants for the entire go-redis library

LogLevelT.DebugOrAbove

func (l LogLevelT) DebugOrAbove() bool

LogLevelT.InfoOrAbove

func (l LogLevelT) InfoOrAbove() bool

LogLevelT.IsValid

func (l LogLevelT) IsValid() bool

IsValid returns true if the log level is valid

LogLevelT.String

func (l LogLevelT) String() string

String returns the string representation of the log level

LogLevelT.WarnOrAbove

func (l LogLevelT) WarnOrAbove() bool

Logging

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

NewDefaultLogger

func NewDefaultLogger(calldepth int) Logging

NewDefaultLogger returns a stderr logger that attributes each line to the frame calldepth levels up the stack.

Once

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

A Once will perform a successful action exactly once.

Unlike a sync.Once, this Once's func returns an error and is re-armed on failure.

Once.Do

func (o *Once) Do(f func() error) error

Do calls the function f if and only if Do has not been invoked without error for this instance of Once. In other words, given

var once Once

if once.Do(f) is called multiple times, only the first call will invoke f, even if f has a different value in each invocation unless f returns an error. A new instance of Once is required for each function to execute.

Do is intended for initialization that must be run exactly once. Since f is niladic, it may be necessary to use a function literal to capture the arguments to a function to be invoked by Do:

err := config.once.Do(func() error { return config.init(filename) })

Dependency graph