redis

package module
Version: v0.0.0-...-1f9eb59 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

README

redisc

Name

redisc - enables a networked cache using Redis.

Description

With redisc responses can be cached for up to 3600s. Caching in Redis is mostly useful in a setup where multiple CoreDNS instances share a VIP. E.g. multiple CoreDNS pods in a Kubernetes cluster.

If Redis is not reachable this plugin will be a noop. The cache and redisc plugin can be used together, where cache is the L1 and redisc is the L2 level cache. If multiple CoreDNS instances get a cache miss for the same item, they will all be fetching the same information from an upstream and updating the cache, i.e. there is no (extra) coordination between those instances.

If Redis is not available CoreDNS will simply not cache anything if metrics are enabled this will be visible in the set_errors_total metric.

Syntax

redisc [TTL] [ZONES...]
  • TTL max TTL in seconds. If not specified, the maximum TTL will be used, which is 3600 for noerror responses and 1800 for denial of existence ones. Setting a TTL of 300: redisc 300 would cache records up to 300 seconds.
  • ZONES zones it should cache for. If empty, the zones from the configuration block are used.

Each element in the Redis cache is cached according to its TTL (with TTL as the max). For the negative cache, the SOA's MinTTL value is used. When no endpoint is specified the default of 127.0.0.1:6379 will be used.

If you want more control:

redisc [TTL] [ZONES...] {
    endpoint ENDPOINT
}
  • TTL and ZONES as above.
  • endpoint specifies which ENDPOINT to use for Redis, this default to 127.0.0.1:6379.

Metrics

If monitoring is enabled (via the prometheus directive) then the following metrics are exported:

  • coredns_redisc_hits_total{server} - Counter of cache hits.
  • coredns_redisc_misses_total{server} - Counter of cache misses.
  • coredns_redisc_set_errors_total{server} - Counter of errors when connecting to Redis.
  • coredns_redisc_drops_total{server} - Counter of dropped messages.

The server label indicates which server handled the request, see the metrics plugin for details.

Examples

Enable caching for all zones, cache locally and also cache for up to 40s in the cluster wide Redis.

. {
    cache 30
    redisc 40 {
        endpoint 10.0.240.1:69
    }
    whoami
}

Proxy to Google Public DNS and only cache responses for example.org (and below).

. {
    proxy . 8.8.8.8:53
    redisc example.org
}

See Also

See the Redis site for more information on Redis. An external plugin called redis already exists, hence this is named redisc, for "redis cache".

Bugs

There is little unit testing.

Documentation

Index

Constants

View Source
const (

	// Success is the class for caching positive caching.
	Success = "success"
	// Denial is the class defined for negative caching.
	Denial = "denial"
)

Variables

This section is empty.

Functions

func Add

func Add(p *pool.Pool, key int, m *dns.Msg, duration time.Duration) error

Add adds the message m under k in Redis.

func FromString

func FromString(s string, ttl int) *dns.Msg

FromString converts s back into a DNS message.

func Get

func Get(p *pool.Pool, key int) (*dns.Msg, error)

Get returns the message under key from Redis.

func ToString

func ToString(m *dns.Msg) string

ToString converts the message m to a bsae64 encoded string.

Types

type Redis

type Redis struct {
	Next  plugin.Handler
	Zones []string
	// contains filtered or unexported fields
}

Redis is plugin that looks up responses in a cache and caches replies. It has a success and a denial of existence cache.

func New

func New() *Redis

New returns an new initialized Redis.

func (*Redis) Name

func (re *Redis) Name() string

Name implements the Handler interface.

func (*Redis) ServeDNS

func (re *Redis) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface.

type ResponseWriter

type ResponseWriter struct {
	dns.ResponseWriter

	*Redis
	// contains filtered or unexported fields
}

ResponseWriter is a response writer that caches the reply message in Redis.

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(buf []byte) (int, error)

Write implements the dns.ResponseWriter interface.

func (*ResponseWriter) WriteMsg

func (w *ResponseWriter) WriteMsg(res *dns.Msg) error

WriteMsg implements the dns.ResponseWriter interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL