otredis

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package otredis provides redis client with opentracing. For documentation about redis usage, see https://github.com/go-redis/redis

package otredis works with redis cluster, redis sentinel and single redis instance.

Integration

package otredis exports the configuration in the following format:

redis:
  default:
    addrs:
      - 127.0.0.1:6379
    DB: 0

To see all available configurations, use the exportConfig command.

Add the redis dependency to core:

var c *core.C = core.New()
c.Provide(otredis.Providers())

Then you can invoke redis from the application.

c.Invoke(func(redisClient redis.UniversalClient) {
	redisClient.Ping(context.Background())
})

Sometimes there are valid reasons to connect to more than one redis server. Inject otredis.Maker to factory a redis.UniversalClient with a specific configuration entry.

c.Invoke(function(maker otredis.Maker) {
	client, err := maker.Make("default")
	// do something with client
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Providers added in v0.2.0

func Providers() []interface{}

Providers returns a set of dependency providers related to redis. It includes the Maker, the default redis.UniversalClient and exported configs.

Depends On:
	log.Logger
	contract.ConfigAccessor
	RedisConfigurationInterceptor `optional:"true"`
	opentracing.Tracer            `optional:"true"`
Provide:
	Maker
	Factory
	redis.UniversalClient

Types

type Factory

type Factory struct {
	*di.Factory
}

Factory is a *di.Factory that creates redis.UniversalClient using a specific configuration entry.

func (Factory) Make

func (r Factory) Make(name string) (redis.UniversalClient, error)

Make creates redis.UniversalClient using a specific configuration entry.

type Maker

type Maker interface {
	Make(name string) (redis.UniversalClient, error)
}

Maker is models Factory

type RedisConfigurationInterceptor

type RedisConfigurationInterceptor func(name string, opts *redis.UniversalOptions)

RedisConfigurationInterceptor intercepts the redis.UniversalOptions before creating the client so you can make amendment to it. Useful because some configuration can not be mapped to a text representation. For example, you cannot add OnConnect callback in a configuration file, but you can add it here.

Jump to

Keyboard shortcuts

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