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 ¶
Factory is a *di.Factory that creates redis.UniversalClient using a specific configuration entry.
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.
type RedisLogAdapter ¶ added in v0.4.0
RedisLogAdapter is an adapter between kitlog and redis logger interface