v1.0.1 Latest Latest

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 5 Imported by: 0



goredis library wrapped in go-redis.

Example of use

Single Redis
	// way 1: redis version 6.0 or above
	redisCli, err := goredis.Init("default:123456@", goredis.WithEnableTrace())
	if err != nil {
		panic("goredis.Init error: " + err.Error())

	// way 2: redis version 5.0 or below
	redisCli := goredis.Init2("", "123456", 0, goredis.WithEnableTrace())

	addrs := []string{"", "", ""}
	rdb := InitSentinel("master", addrs, "default", "123456", goredis.WithEnableTrace())

	addrs := []string{"", "", ""}
	clusterRdb := InitCluster(addrs, "default", "123456", goredis.WithEnableTrace())

Official Documents https://redis.uptrace.dev/zh/guide/go-redis.html



Package goredis is a library wrapped on top of github.com/go-redis/redis.



View Source
const (
	// ErrRedisNotFound not exist in redis
	ErrRedisNotFound = redis.Nil
	// DefaultRedisName default redis name
	DefaultRedisName = "default"


This section is empty.


func Init

func Init(dsn string, opts ...Option) (*redis.Client, error)

Init connecting to redis dsn supported formats. (1) no password, no db: localhost:6379 (2) with password and db: <user>:<pass>@localhost:6379/2 (3) redis://default:123456@localhost:6379/0?max_retries=3 for more parameters see the redis source code for the setupConnParams function

func Init2

func Init2(addr string, password string, db int, opts ...Option) *redis.Client

Init2 connecting to redis

func InitCluster

func InitCluster(addrs []string, username string, password string, opts ...Option) *redis.ClusterClient

InitCluster connecting to redis for cluster, all redis username and password are the same

func InitSentinel

func InitSentinel(masterName string, addrs []string, username string, password string, opts ...Option) *redis.Client

InitSentinel connecting to redis for sentinel, all redis username and password are the same


type Option

type Option func(*options)

Option set the redis options.

func WithDialTimeout

func WithDialTimeout(t time.Duration) Option

WithDialTimeout set dail timeout

func WithEnableTrace

func WithEnableTrace() Option

WithEnableTrace use trace

func WithReadTimeout

func WithReadTimeout(t time.Duration) Option

WithReadTimeout set read timeout

func WithTLSConfig

func WithTLSConfig(c *tls.Config) Option

WithTLSConfig set TLS config

func WithWriteTimeout

func WithWriteTimeout(t time.Duration) Option

WithWriteTimeout set write timeout

Jump to

Keyboard shortcuts

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