goredis

package
v1.0.1 Latest Latest
Warning

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

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", goredis.WithEnableTrace())
	if err != nil {
		panic("goredis.Init error: " + err.Error())
	}

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

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

Cluster
	addrs := []string{"127.0.0.1:6380", "127.0.0.1:6381", "127.0.0.1:6382"}
	clusterRdb := InitCluster(addrs, "default", "123456", goredis.WithEnableTrace())

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 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

Types

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