Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StringToBytes ¶
StringToBytes converts string to byte slice. (copied from vendor/github.com/go-redis/redis/v8/internal/util/unsafe.go)
Types ¶
type BackgroundConfig ¶
type BackgroundConfig struct { WriteBackGoroutines int `yaml:"writeback_goroutines"` WriteBackBuffer int `yaml:"writeback_buffer"` }
BackgroundConfig is config for a Background Cache.
func (*BackgroundConfig) RegisterFlagsWithPrefix ¶
func (cfg *BackgroundConfig) RegisterFlagsWithPrefix(prefix string, description string, f *flag.FlagSet)
RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet
type Cache ¶
type Cache interface { Store(ctx context.Context, key []string, buf [][]byte) Fetch(ctx context.Context, keys []string) (found []string, bufs [][]byte, missing []string) Stop() }
Cache byte arrays by key.
NB we intentionally do not return errors in this interface - caching is best effort by definition. We found that when these methods did return errors, the caller would just log them - so its easier for implementation to do that. Whats-more, we found partially successful Fetchs were often treated as failed when they returned an error.
func NewBackground ¶
func NewBackground(name string, cfg BackgroundConfig, cache Cache, reg prometheus.Registerer) Cache
NewBackground returns a new Cache that does stores on background goroutines.
type Memcached ¶
type Memcached struct {
// contains filtered or unexported fields
}
Memcached type caches chunks in memcached
func NewMemcached ¶
func NewMemcached(cfg MemcachedConfig, client MemcachedClient, name string, reg prometheus.Registerer, logger log.Logger) *Memcached
NewMemcached makes a new Memcached.
type MemcachedClient ¶
type MemcachedClient interface { GetMulti(keys []string) (map[string]*memcache.Item, error) Set(item *memcache.Item) error }
MemcachedClient interface exists for mocking memcacheClient.
func NewMemcachedClient ¶
func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Registerer, logger log.Logger) MemcachedClient
NewMemcachedClient creates a new MemcacheClient that gets its server list from SRV and updates the server list on a regular basis.
type MemcachedClientConfig ¶
type MemcachedClientConfig struct { Host string `yaml:"host"` Service string `yaml:"service"` Addresses string `yaml:"addresses"` // EXPERIMENTAL. Timeout time.Duration `yaml:"timeout"` MaxIdleConns int `yaml:"max_idle_conns"` MaxItemSize int `yaml:"max_item_size"` UpdateInterval time.Duration `yaml:"update_interval"` ConsistentHash bool `yaml:"consistent_hash"` CBFailures uint `yaml:"circuit_breaker_consecutive_failures"` CBTimeout time.Duration `yaml:"circuit_breaker_timeout"` // reset error count after this long CBInterval time.Duration `yaml:"circuit_breaker_interval"` // remain closed for this long after CBFailures errors }
MemcachedClientConfig defines how a MemcachedClient should be constructed.
func (*MemcachedClientConfig) RegisterFlagsWithPrefix ¶
func (cfg *MemcachedClientConfig) RegisterFlagsWithPrefix(prefix, description string, f *flag.FlagSet)
RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet
type MemcachedConfig ¶
type MemcachedConfig struct { Expiration time.Duration `yaml:"expiration"` BatchSize int `yaml:"batch_size"` Parallelism int `yaml:"parallelism"` }
MemcachedConfig is config to make a Memcached
func (*MemcachedConfig) RegisterFlagsWithPrefix ¶
func (cfg *MemcachedConfig) RegisterFlagsWithPrefix(prefix, description string, f *flag.FlagSet)
RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet
type MemcachedJumpHashSelector ¶
type MemcachedJumpHashSelector struct {
// contains filtered or unexported fields
}
MemcachedJumpHashSelector implements the memcache.ServerSelector interface. MemcachedJumpHashSelector utilizes a jump hash to distribute keys to servers.
While adding or removing servers only requires 1/N keys to move, servers are treated as a stack and can only be pushed/popped. Therefore, MemcachedJumpHashSelector works best for servers with consistent DNS names where the naturally sorted order is predictable.
func (*MemcachedJumpHashSelector) Each ¶
func (s *MemcachedJumpHashSelector) Each(f func(net.Addr) error) error
Each iterates over each server and calls the given function. If f returns a non-nil error, iteration will stop and that error will be returned.
func (*MemcachedJumpHashSelector) PickServer ¶
func (s *MemcachedJumpHashSelector) PickServer(key string) (net.Addr, error)
PickServer returns the server address that a given item should be shared onto.
func (*MemcachedJumpHashSelector) SetServers ¶
func (s *MemcachedJumpHashSelector) SetServers(servers ...string) error
SetServers changes a MemcachedJumpHashSelector's set of servers at runtime and is safe for concurrent use by multiple goroutines.
Each server is given equal weight. A server is given more weight if it's listed multiple times.
SetServers returns an error if any of the server names fail to resolve. No attempt is made to connect to the server. If any error occurs, no changes are made to the internal server list.
To minimize the number of rehashes for keys when scaling the number of servers in subsequent calls to SetServers, servers are stored in natural sort order.
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache type caches chunks in redis
func NewRedisCache ¶
func NewRedisCache(name string, redisClient *RedisClient, reg prometheus.Registerer, logger log.Logger) *RedisCache
NewRedisCache creates a new RedisCache
type RedisClient ¶
type RedisClient struct {
// contains filtered or unexported fields
}
func NewRedisClient ¶
func NewRedisClient(cfg *RedisConfig) *RedisClient
NewRedisClient creates Redis client
func (*RedisClient) Close ¶
func (c *RedisClient) Close() error
type RedisConfig ¶
type RedisConfig struct { Endpoint string `yaml:"endpoint"` MasterName string `yaml:"master_name"` Timeout time.Duration `yaml:"timeout"` Expiration time.Duration `yaml:"expiration"` DB int `yaml:"db"` PoolSize int `yaml:"pool_size"` Username string `yaml:"username"` Password flagext.Secret `yaml:"password"` SentinelUsername string `yaml:"sentinel_username"` SentinelPassword flagext.Secret `yaml:"sentinel_password"` EnableTLS bool `yaml:"tls_enabled"` InsecureSkipVerify bool `yaml:"tls_insecure_skip_verify"` IdleTimeout time.Duration `yaml:"idle_timeout"` MaxConnAge time.Duration `yaml:"max_connection_age"` }
RedisConfig defines how a RedisCache should be constructed.
func (*RedisConfig) RegisterFlagsWithPrefix ¶
func (cfg *RedisConfig) RegisterFlagsWithPrefix(prefix, description string, f *flag.FlagSet)
RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet