func (c *RedisCache) Close() error {
	return c.backend.Close()
}
Close closes underlying connections
package lcw
import (
	"sync/atomic"
	"time"
	"github.com/go-redis/redis/v7"
	"github.com/pkg/errors"
)
const RedisValueSizeLimit = 512 * 1024 * 1024
type RedisCache struct {
	options
	CacheStat
	backend *redis.Client
}
func NewRedisCache(backend *redis.Client, opts ...Option) (*RedisCache, error) {
	res := RedisCache{
		options: options{
			ttl: 5 * time.Minute,
		},
	}
	for _, opt := range opts {
		if err := opt(&res.options); err != nil {
			return nil, errors.Wrap(err, "failed to set cache option")
		}
	}
	if res.maxValueSize <= 0 || res.maxValueSize > RedisValueSizeLimit {
		res.maxValueSize = RedisValueSizeLimit
	}
	res.backend = backend
	return &res, nil
}
func (c *RedisCache) Get(key string, fn func() (interface{}, error)) (data interface{}, err error) {
	v, getErr := c.backend.Get(key).Result()
	switch getErr {
	case nil:
		atomic.AddInt64(&c.Hits, 1)
		return v, nil
	case redis.Nil:
		if data, err = fn(); err != nil {
			atomic.AddInt64(&c.Errors, 1)
			return data, err
		}
	default:
		atomic.AddInt64(&c.Errors, 1)
		return v, getErr
	}
	atomic.AddInt64(&c.Misses, 1)
	if !c.allowed(key, data) {
		return data, nil
	}
	_, setErr := c.backend.Set(key, data, c.ttl).Result()
	if setErr != nil {
		atomic.AddInt64(&c.Errors, 1)
		return data, setErr
	}
	return data, nil
}
func (c *RedisCache) Invalidate(fn func(key string) bool) {
	for _, key := range c.backend.Keys("*").Val() {  
		if fn(key) {
			c.backend.Del(key)
		}
	}
}
func (c *RedisCache) Peek(key string) (interface{}, bool) {
	ret, err := c.backend.Get(key).Result()
	if err != nil {
		return nil, false
	}
	return ret, true
}
func (c *RedisCache) Purge() {
	c.backend.FlushDB()
}
func (c *RedisCache) Delete(key string) {
	c.backend.Del(key)
}
func (c *RedisCache) Keys() (res []string) {
	return c.backend.Keys("*").Val()
}
func (c *RedisCache) Stat() CacheStat {
	return CacheStat{
		Hits:   c.Hits,
		Misses: c.Misses,
		Size:   c.size(),
		Keys:   c.keys(),
		Errors: c.Errors,
	}
}