goredis

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 8 Imported by: 0

README

goredis

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@127.0.0.1:6379") // can set parameters such as timeout, tls, tracing, such as goredis.Withxxx()
	if err != nil {
		panic("goredis.Init error: " + err.Error())
	}

	// way 2: redis version 5.0 or below
	redisCli, err := goredis.InitSingle("127.0.0.1:6379", "123456", 0) // can set parameters such as timeout, tls, tracing, such as goredis.Withxxx()

Sentinel
	addrs := []string{"127.0.0.1:6380", "127.0.0.1:6381", "127.0.0.1:6382","127.0.0.1:26380", "127.0.0.1:26381", "127.0.0.1:26382"}
	rdbCli, err : := goredis.InitSentinel("mymaster", addrs, "", "123456") // can set parameters such as timeout, tls, tracing, such as goredis.Withxxx()

Cluster
	addrs := []string{"127.0.0.1:6380", "127.0.0.1:6381", "127.0.0.1:6382","127.0.0.1:6383", "127.0.0.1:6384", "127.0.0.1:6385"}
	clusterRdb, err : := goredis.InitCluster(addrs, "", "123456") // can set parameters such as timeout, tls, tracing, such as goredis.Withxxx()

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

Documentation

Overview

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

Index

Constants

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

Variables

This section is empty.

Functions

func Close

func Close(rdb *redis.Client) error

Close redis client

func CloseCluster

func CloseCluster(clusterRdb *redis.ClusterClient) error

CloseCluster redis cluster client

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 InitCluster

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

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, error)

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

func InitSingle

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

InitSingle connecting to single redis instance

Types

type Client

type Client = redis.Client

Client is a redis client

type Option

type Option func(*options)

Option set the redis options.

func WithClusterOptions

func WithClusterOptions(opt *redis.ClusterOptions) Option

WithClusterOptions set redis cluster options

func WithDialTimeout

func WithDialTimeout(t time.Duration) Option

WithDialTimeout set dail timeout

func WithEnableTrace

func WithEnableTrace() Option

WithEnableTrace use trace, redis v8 Deprecated: use WithEnableTracer instead

func WithReadTimeout

func WithReadTimeout(t time.Duration) Option

WithReadTimeout set read timeout

func WithSentinelOptions

func WithSentinelOptions(opt *redis.FailoverOptions) Option

WithSentinelOptions set redis sentinel options

func WithSingleOptions

func WithSingleOptions(opt *redis.Options) Option

WithSingleOptions set single redis options

func WithTLSConfig

func WithTLSConfig(c *tls.Config) Option

WithTLSConfig set TLS config

func WithTracing

func WithTracing(tp *trace.TracerProvider) Option

WithTracing set redis tracer provider, redis v9

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