Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRedisCacheNotInstantiated = errors.New("redis client not instantiated, call NewRedisCacheInstance first")
Functions ¶
Types ¶
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache is a struct which holds some defaults for cache entries, such as the ttl and a prefix for each key. The idea here is that you have can have multiple instances of this struct and they all use the one client in this pacakge.
func NewRedisCacheInstance ¶
func NewRedisCacheInstance(keyPrefix string, ttl time.Duration) (*RedisCache, error)
func (*RedisCache) Add ¶
func (c *RedisCache) Add(ctx context.Context, key string, value interface{})
Add adds a key-value pair to the cache. This is specifically made to implement the PersistedQueryCache of gqlgen, so you can pass an instance of RedisCache to gqlgen. If you are wanting to manipulate the redis cache more directly, you may wish to use Set instead.
func (*RedisCache) Get ¶
func (c *RedisCache) Get(ctx context.Context, key string) (interface{}, bool)
Gets a key-value pair from the cache. Part of the implementation of gqlgen's PersistedQueryCache so you can pass an isntance of RedisCache to a gqlgen handler.
func (*RedisCache) Set ¶
func (c *RedisCache) Set(key string, value interface{}) error
Set adds a key-value pair to the cache. Main difference between this and Add is that it returns an error, which makes it more useful than Add outside of using it with gqlgen.