redis

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 7 Imported by: 0

README

redis

Redis client helpers.

Usage

client, err := redis.NewClient(redis.Config{
	Addr: "localhost:6379",
})
if err != nil {
	return err
}

TLS

Config.TLSConfig is optional. Leave it nil for local Redis on loopback or another trusted private link.

Set TLSConfig when Redis is reached across an untrusted network or when a managed Redis provider requires TLS:

client, err := redis.NewClient(redis.Config{
	Addr: "redis.example.com:6379",
	TLSConfig: &tls.Config{
		ServerName: "redis.example.com",
	},
})

Notes

  • Addr is required.
  • Ping expects an explicit non-nil context.Context.

Documentation

Overview

Package redis provides Redis client helpers. Package redis 提供 Redis 客户端辅助函数。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(cfg Config) (*redis.Client, error)

NewClient returns a Redis client. Call NewClient(Config{Addr: "host:port"}). NewClient 返回 Redis client。 调用 NewClient(Config{Addr: "host:port"})。

Example / 示例:

client, _ := redis.NewClient(redis.Config{Addr: "localhost:6379"})

func Ping

func Ping(ctx context.Context, client *redis.Client) error

Ping checks Redis connectivity. Ping 检查 Redis 连通性。

Types

type Config

type Config struct {
	Addr         string
	Username     string
	Password     string
	DB           int
	PoolSize     int
	MinIdleConns int
	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	TLSConfig    *tls.Config
}

Config configures NewClient. Config 配置 NewClient。

Jump to

Keyboard shortcuts

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