MCPcopy Create free account
hub / github.com/cortexproject/cortex / NewRedisCache

Function NewRedisCache

pkg/chunk/cache/redis_cache.go:26–45  ·  view source on GitHub ↗

NewRedisCache creates a new RedisCache

(name string, redisClient *RedisClient, reg prometheus.Registerer, logger log.Logger)

Source from the content-addressed store, hash-verified

24
25// NewRedisCache creates a new RedisCache
26func NewRedisCache(name string, redisClient *RedisClient, reg prometheus.Registerer, logger log.Logger) *RedisCache {
27 cache := &RedisCache{
28 name: name,
29 redis: redisClient,
30 logger: logger,
31 requestDuration: instr.NewHistogramCollector(
32 promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
33 Namespace: "cortex",
34 Name: "rediscache_request_duration_seconds",
35 Help: "Total time spent in seconds doing Redis requests.",
36 Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8),
37 ConstLabels: prometheus.Labels{"name": name},
38 }, []string{"method", "status_code"}),
39 ),
40 }
41 if err := cache.redis.Ping(context.Background()); err != nil {
42 level.Error(logger).Log("msg", "error connecting to redis", "name", name, "err", err)
43 }
44 return cache
45}
46
47func redisStatusCode(err error) string {
48 // TODO: Figure out if there are more error types returned by Redis

Callers 2

NewFunction · 0.85
mockRedisCacheFunction · 0.85

Calls 3

PingMethod · 0.80
LogMethod · 0.45
ErrorMethod · 0.45

Tested by 1

mockRedisCacheFunction · 0.68