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.Provide)
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 ¶
This section is empty.
Types ¶
type Factory ¶
Factory is a *di.Factory that 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.
type RedisIn ¶
type RedisIn struct {
di.In
Logger log.Logger
Conf contract.ConfigAccessor
Interceptor RedisConfigurationInterceptor `optional:"true"`
Tracer opentracing.Tracer `optional:"true"`
}
RedisIn is the injection parameter for Provide.
type RedisOut ¶
type RedisOut struct {
di.Out
Maker Maker
Factory Factory
Client redis.UniversalClient
ExportedConfig []config.ExportedConfig `group:"config,flatten"`
}
RedisOut is the result of Provide.