Documentation
¶
Index ¶
- Variables
- type Client
- type Mock
- func (m *Mock) Add(ctx context.Context, key string, data interface{}, expiration time.Time) error
- func (m *Mock) Decrement(ctx context.Context, key string, delta uint64) (uint64, error)
- func (m *Mock) Delete(ctx context.Context, key string) error
- func (m *Mock) Get(ctx context.Context, key string, data interface{}) error
- func (m *Mock) Increment(ctx context.Context, key string, delta uint64) (uint64, error)
- func (m *Mock) Set(ctx context.Context, key string, data interface{}, expiration time.Time) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCacheMiss = errors.New("cache miss") ErrNotStored = errors.New("not stored") ErrNotAPointer = errors.New("argument to Get() must be a pointer") ErrNotANumber = errors.New("value currently stored is not a number") )
View Source
var NeverExpire time.Time
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// Get gets the item for the given key.
// Returns ErrCacheMiss for a cache miss.
// The key must be at most 250 bytes in length.
Get(ctx context.Context, key string, data interface{}) error
// Set writes the given item, unconditionally.
Set(ctx context.Context, key string, data interface{}, expiration time.Time) error
// Add writes the given item, if no value already exists for its
// key. ErrNotStored is returned if that condition is not met.
Add(ctx context.Context, key string, data interface{}, expiration time.Time) error
// Delete deletes the item with the provided key, if it exists.
Delete(ctx context.Context, key string) error
// Increment adds delta to the currently stored number
// If the key does not exist, it will be initialized to 0 with no expiration.
// If the value overflows, it will loop around from 0
// For many client implementations, you need to be using a LiteralEncoding for this feature to work
Increment(ctx context.Context, key string, delta uint64) (uint64, error)
// Decrement subtracts delta to the currently stored number
// If the key does not exist, it will be initialized to 0 with no expiration, which will make it overflow.
// If the value overflows, it will loop around from MaxUint64
// For many client implementations, you need to be using a LiteralEncoding for this feature to work
Decrement(ctx context.Context, key string, delta uint64) (uint64, error)
}
Client is inspired from *memcached.Client
func NewMemcacheClient ¶
func NewMemcacheClient(c *memcache.Client, enc encoding.ValueEncoding) Client
Example ¶
memcacheClient := memcache.New("localhost:11211")
NewMemcacheClient(memcacheClient, encoding.NewValueEncoding(encoding.GobEncoding))
func NewMemoryClient ¶
func NewMemoryClient() Client
NewMemoryClient returns a Client that only stores in memory. Useful for stubbing tests.
func NewPrefixClient ¶ added in v2.1.0
NewPrefixClient returns a Client that adds a prefix to all keys
func NewRedisClient ¶
func NewRedisClient(c *redis.Client, enc encoding.ValueEncoding) Client
Example ¶
opts, err := redis.ParseURL("")
if err != nil {
panic(err)
}
client := redis.NewClient(opts)
NewRedisClient(client, encoding.NewValueEncoding(encoding.GobEncoding))
Source Files
¶
Click to show internal directories.
Click to hide internal directories.