Documentation ¶
Overview ¶
Package cache is a generated GoMock package.
Index ¶
- Constants
- type GoRedisCluster
- func (r *GoRedisCluster) Close()
- func (r *GoRedisCluster) Del(ctx context.Context, key ...interface{}) (int64, error)
- func (r *GoRedisCluster) Exists(ctx context.Context, key string) (bool, error)
- func (r *GoRedisCluster) Expire(ctx context.Context, key string, seconds int64) (bool, error)
- func (r *GoRedisCluster) Get(ctx context.Context, key string) ([]byte, error)
- func (r *GoRedisCluster) HExists(ctx context.Context, key, field string) (bool, error)
- func (r *GoRedisCluster) HGet(ctx context.Context, key, field string) ([]byte, error)
- func (r *GoRedisCluster) HSet(ctx context.Context, key, field, value string) (bool, error)
- func (r *GoRedisCluster) SetEX(ctx context.Context, key string, seconds int64, value string) error
- func (r *GoRedisCluster) SetNX(ctx context.Context, key string, seconds int64, value string) (bool, error)
- func (r *GoRedisCluster) TTL(ctx context.Context, key string) (int64, error)
- type MockRedisClientItf
- func (m *MockRedisClientItf) Close()
- func (m *MockRedisClientItf) Del(ctx context.Context, key ...interface{}) (int64, error)
- func (m *MockRedisClientItf) EXPECT() *MockRedisClientItfMockRecorder
- func (m *MockRedisClientItf) Exists(ctx context.Context, key string) (bool, error)
- func (m *MockRedisClientItf) Expire(ctx context.Context, key string, seconds int64) (bool, error)
- func (m *MockRedisClientItf) Get(ctx context.Context, key string) ([]byte, error)
- func (m *MockRedisClientItf) HExists(ctx context.Context, key, field string) (bool, error)
- func (m *MockRedisClientItf) HGet(ctx context.Context, key, field string) ([]byte, error)
- func (m *MockRedisClientItf) HSet(ctx context.Context, key, field, value string) (bool, error)
- func (m *MockRedisClientItf) SetEX(ctx context.Context, key string, seconds int64, value string) error
- func (m *MockRedisClientItf) SetNX(ctx context.Context, key string, seconds int64, value string) (bool, error)
- func (m *MockRedisClientItf) TTL(ctx context.Context, key string) (int64, error)
- type MockRedisClientItfMockRecorder
- func (mr *MockRedisClientItfMockRecorder) Close() *gomock.Call
- func (mr *MockRedisClientItfMockRecorder) Del(ctx interface{}, key ...interface{}) *gomock.Call
- func (mr *MockRedisClientItfMockRecorder) Exists(ctx, key interface{}) *gomock.Call
- func (mr *MockRedisClientItfMockRecorder) Expire(ctx, key, seconds interface{}) *gomock.Call
- func (mr *MockRedisClientItfMockRecorder) Get(ctx, key interface{}) *gomock.Call
- func (mr *MockRedisClientItfMockRecorder) HExists(ctx, key, field interface{}) *gomock.Call
- func (mr *MockRedisClientItfMockRecorder) HGet(ctx, key, field interface{}) *gomock.Call
- func (mr *MockRedisClientItfMockRecorder) HSet(ctx, key, field, value interface{}) *gomock.Call
- func (mr *MockRedisClientItfMockRecorder) SetEX(ctx, key, seconds, value interface{}) *gomock.Call
- func (mr *MockRedisClientItfMockRecorder) SetNX(ctx, key, seconds, value interface{}) *gomock.Call
- func (mr *MockRedisClientItfMockRecorder) TTL(ctx, key interface{}) *gomock.Call
- type MockRistrettoClientItf
- func (m *MockRistrettoClientItf) Clear(ctx context.Context)
- func (m *MockRistrettoClientItf) Close()
- func (m *MockRistrettoClientItf) Del(ctx context.Context, key string)
- func (m *MockRistrettoClientItf) EXPECT() *MockRistrettoClientItfMockRecorder
- func (m *MockRistrettoClientItf) Get(ctx context.Context, key string) (interface{}, bool)
- func (m *MockRistrettoClientItf) Set(ctx context.Context, key string, value interface{}) bool
- func (m *MockRistrettoClientItf) SetEX(ctx context.Context, key string, value interface{}, TTL time.Duration) bool
- type MockRistrettoClientItfMockRecorder
- func (mr *MockRistrettoClientItfMockRecorder) Clear(ctx interface{}) *gomock.Call
- func (mr *MockRistrettoClientItfMockRecorder) Close() *gomock.Call
- func (mr *MockRistrettoClientItfMockRecorder) Del(ctx, key interface{}) *gomock.Call
- func (mr *MockRistrettoClientItfMockRecorder) Get(ctx, key interface{}) *gomock.Call
- func (mr *MockRistrettoClientItfMockRecorder) Set(ctx, key, value interface{}) *gomock.Call
- func (mr *MockRistrettoClientItfMockRecorder) SetEX(ctx, key, value, TTL interface{}) *gomock.Call
- type Redigo
- func (r *Redigo) Close()
- func (r *Redigo) Decr(_ context.Context, key string) (int64, error)
- func (r *Redigo) Del(_ context.Context, key ...interface{}) (int64, error)
- func (r *Redigo) Exists(_ context.Context, key string) (bool, error)
- func (r *Redigo) Expire(_ context.Context, key string, seconds int64) (bool, error)
- func (r *Redigo) ExpireAt(_ context.Context, key string, timestamp int64) (bool, error)
- func (r *Redigo) Get(_ context.Context, key string) ([]byte, error)
- func (r *Redigo) HDel(_ context.Context, key string, fields ...string) (int64, error)
- func (r *Redigo) HExists(_ context.Context, key, field string) (bool, error)
- func (r *Redigo) HGet(_ context.Context, key, field string) ([]byte, error)
- func (r *Redigo) HGetAll(_ context.Context, key string) (map[string]string, error)
- func (r *Redigo) HKeys(_ context.Context, key string) ([]string, error)
- func (r *Redigo) HMGet(_ context.Context, key string, fields ...string) ([][]byte, error)
- func (r *Redigo) HSet(_ context.Context, key, field, value string) (bool, error)
- func (r *Redigo) Incr(_ context.Context, key string) (int64, error)
- func (r *Redigo) IncrByEx(_ context.Context, key string, by int64, expires int64) (int64, error)
- func (r *Redigo) LRange(_ context.Context, key string, start, stop int64) ([][]byte, error)
- func (r *Redigo) LTrim(_ context.Context, key string, start, stop int64) error
- func (r *Redigo) Publish(_ context.Context, topic, message string) (int, error)
- func (r *Redigo) SAdd(_ context.Context, key string, value ...string) (bool, error)
- func (r *Redigo) SetEX(_ context.Context, key string, seconds int64, value string) error
- func (r *Redigo) SetNX(_ context.Context, key string, seconds int64, value string) (bool, error)
- func (r *Redigo) SimpleSet(_ context.Context, key, value string) error
- func (r *Redigo) TTL(_ context.Context, key string) (int64, error)
- type RedisClientItf
- type RedisConfiguration
- type RedisMigrator
- func (r *RedisMigrator) Close()
- func (r *RedisMigrator) Del(ctx context.Context, key ...interface{}) (int64, error)
- func (r *RedisMigrator) Exists(ctx context.Context, key string) (bool, error)
- func (r *RedisMigrator) Expire(ctx context.Context, key string, seconds int64) (bool, error)
- func (r *RedisMigrator) Get(ctx context.Context, key string) ([]byte, error)
- func (r *RedisMigrator) HExists(ctx context.Context, key, field string) (bool, error)
- func (r *RedisMigrator) HGet(ctx context.Context, key, field string) ([]byte, error)
- func (r *RedisMigrator) HSet(ctx context.Context, key, field, value string) (bool, error)
- func (r *RedisMigrator) SetEX(ctx context.Context, key string, seconds int64, value string) error
- func (r *RedisMigrator) SetNX(ctx context.Context, key string, seconds int64, value string) (bool, error)
- func (r *RedisMigrator) TTL(ctx context.Context, key string) (int64, error)
- type Ristretto
- func (r *Ristretto) Clear(_ context.Context)
- func (r *Ristretto) Close()
- func (r *Ristretto) Del(_ context.Context, key string)
- func (r *Ristretto) Get(_ context.Context, key string) (res interface{}, exists bool)
- func (r *Ristretto) Set(_ context.Context, key string, value interface{}) bool
- func (r *Ristretto) SetEX(_ context.Context, key string, value interface{}, ttl time.Duration) bool
- type RistrettoClientItf
- type RistrettoConfiguration
Constants ¶
const ( TTLRedisOneSecond = int64(1) TTLRedisOneMinute = 60 * TTLRedisOneSecond TTLRedisFiveMinutes = 5 * TTLRedisOneMinute TTLRedisTenMinutes = 10 * TTLRedisOneMinute TTLRedisFifteenMinutes = 15 * TTLRedisOneMinute TTLRedisThirtyMinutes = 30 * TTLRedisOneMinute TTLRedisSeventyFiveMinutes = 75 * TTLRedisOneMinute TTLRedisOneHour = 60 * TTLRedisOneMinute TTLRedisHalfDay = 12 * TTLRedisOneHour TTLRedisOneDay = 24 * TTLRedisOneHour TTLRedisThreeDays = 3 * TTLRedisOneDay TTLRedisOneWeek = 7 * TTLRedisOneDay TTLRedisOneMonth = 30 * TTLRedisOneDay )
Time use for redis ttl which by default is in time.Second.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GoRedisCluster ¶
type GoRedisCluster struct {
// contains filtered or unexported fields
}
GoRedisCluster returns a redis cluster client using go-redis library.
func NewGoRedisCluster ¶
func NewGoRedisCluster(config *RedisConfiguration) (*GoRedisCluster, error)
NewGoRedisCluster returns a redis cluster client.
func (*GoRedisCluster) Close ¶
func (r *GoRedisCluster) Close()
Close closes the client, releasing any open resources.
func (*GoRedisCluster) Del ¶
func (r *GoRedisCluster) Del(ctx context.Context, key ...interface{}) (int64, error)
Del deletes a key.
func (*GoRedisCluster) SetEX ¶
func (r *GoRedisCluster) SetEX( ctx context.Context, key string, seconds int64, value string, ) error
SetEX sets the value to a key with timeout in seconds.
type MockRedisClientItf ¶
type MockRedisClientItf struct {
// contains filtered or unexported fields
}
MockRedisClientItf is a mock of RedisClientItf interface.
func NewMockRedisClientItf ¶
func NewMockRedisClientItf(ctrl *gomock.Controller) *MockRedisClientItf
NewMockRedisClientItf creates a new mock instance.
func (*MockRedisClientItf) Del ¶
func (m *MockRedisClientItf) Del(ctx context.Context, key ...interface{}) (int64, error)
Del mocks base method.
func (*MockRedisClientItf) EXPECT ¶
func (m *MockRedisClientItf) EXPECT() *MockRedisClientItfMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockRedisClientItf) SetEX ¶
func (m *MockRedisClientItf) SetEX(ctx context.Context, key string, seconds int64, value string) error
SetEX mocks base method.
type MockRedisClientItfMockRecorder ¶
type MockRedisClientItfMockRecorder struct {
// contains filtered or unexported fields
}
MockRedisClientItfMockRecorder is the mock recorder for MockRedisClientItf.
func (*MockRedisClientItfMockRecorder) Close ¶
func (mr *MockRedisClientItfMockRecorder) Close() *gomock.Call
Close indicates an expected call of Close.
func (*MockRedisClientItfMockRecorder) Del ¶
func (mr *MockRedisClientItfMockRecorder) Del(ctx interface{}, key ...interface{}) *gomock.Call
Del indicates an expected call of Del.
func (*MockRedisClientItfMockRecorder) Exists ¶
func (mr *MockRedisClientItfMockRecorder) Exists(ctx, key interface{}) *gomock.Call
Exists indicates an expected call of Exists.
func (*MockRedisClientItfMockRecorder) Expire ¶
func (mr *MockRedisClientItfMockRecorder) Expire(ctx, key, seconds interface{}) *gomock.Call
Expire indicates an expected call of Expire.
func (*MockRedisClientItfMockRecorder) Get ¶
func (mr *MockRedisClientItfMockRecorder) Get(ctx, key interface{}) *gomock.Call
Get indicates an expected call of Get.
func (*MockRedisClientItfMockRecorder) HExists ¶
func (mr *MockRedisClientItfMockRecorder) HExists(ctx, key, field interface{}) *gomock.Call
HExists indicates an expected call of HExists.
func (*MockRedisClientItfMockRecorder) HGet ¶
func (mr *MockRedisClientItfMockRecorder) HGet(ctx, key, field interface{}) *gomock.Call
HGet indicates an expected call of HGet.
func (*MockRedisClientItfMockRecorder) HSet ¶
func (mr *MockRedisClientItfMockRecorder) HSet(ctx, key, field, value interface{}) *gomock.Call
HSet indicates an expected call of HSet.
func (*MockRedisClientItfMockRecorder) SetEX ¶
func (mr *MockRedisClientItfMockRecorder) SetEX(ctx, key, seconds, value interface{}) *gomock.Call
SetEX indicates an expected call of SetEX.
func (*MockRedisClientItfMockRecorder) SetNX ¶
func (mr *MockRedisClientItfMockRecorder) SetNX(ctx, key, seconds, value interface{}) *gomock.Call
SetNX indicates an expected call of SetNX.
func (*MockRedisClientItfMockRecorder) TTL ¶
func (mr *MockRedisClientItfMockRecorder) TTL(ctx, key interface{}) *gomock.Call
TTL indicates an expected call of TTL.
type MockRistrettoClientItf ¶
type MockRistrettoClientItf struct {
// contains filtered or unexported fields
}
MockRistrettoClientItf is a mock of RistrettoClientItf interface.
func NewMockRistrettoClientItf ¶
func NewMockRistrettoClientItf(ctrl *gomock.Controller) *MockRistrettoClientItf
NewMockRistrettoClientItf creates a new mock instance.
func (*MockRistrettoClientItf) Clear ¶
func (m *MockRistrettoClientItf) Clear(ctx context.Context)
Clear mocks base method.
func (*MockRistrettoClientItf) Close ¶
func (m *MockRistrettoClientItf) Close()
Close mocks base method.
func (*MockRistrettoClientItf) Del ¶
func (m *MockRistrettoClientItf) Del(ctx context.Context, key string)
Del mocks base method.
func (*MockRistrettoClientItf) EXPECT ¶
func (m *MockRistrettoClientItf) EXPECT() *MockRistrettoClientItfMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockRistrettoClientItf) Get ¶
func (m *MockRistrettoClientItf) Get(ctx context.Context, key string) (interface{}, bool)
Get mocks base method.
type MockRistrettoClientItfMockRecorder ¶
type MockRistrettoClientItfMockRecorder struct {
// contains filtered or unexported fields
}
MockRistrettoClientItfMockRecorder is the mock recorder for MockRistrettoClientItf.
func (*MockRistrettoClientItfMockRecorder) Clear ¶
func (mr *MockRistrettoClientItfMockRecorder) Clear(ctx interface{}) *gomock.Call
Clear indicates an expected call of Clear.
func (*MockRistrettoClientItfMockRecorder) Close ¶
func (mr *MockRistrettoClientItfMockRecorder) Close() *gomock.Call
Close indicates an expected call of Close.
func (*MockRistrettoClientItfMockRecorder) Del ¶
func (mr *MockRistrettoClientItfMockRecorder) Del(ctx, key interface{}) *gomock.Call
Del indicates an expected call of Del.
func (*MockRistrettoClientItfMockRecorder) Get ¶
func (mr *MockRistrettoClientItfMockRecorder) Get(ctx, key interface{}) *gomock.Call
Get indicates an expected call of Get.
func (*MockRistrettoClientItfMockRecorder) Set ¶
func (mr *MockRistrettoClientItfMockRecorder) Set(ctx, key, value interface{}) *gomock.Call
Set indicates an expected call of Set.
func (*MockRistrettoClientItfMockRecorder) SetEX ¶
func (mr *MockRistrettoClientItfMockRecorder) SetEX(ctx, key, value, TTL interface{}) *gomock.Call
SetEX indicates an expected call of SetEX.
type Redigo ¶
type Redigo struct {
// contains filtered or unexported fields
}
Redigo returns a redis client using redigo library.
func NewRedigo ¶
func NewRedigo(config *RedisConfiguration) (*Redigo, error)
NewRedigo return a redis client.
func (*Redigo) Close ¶
func (r *Redigo) Close()
Close closes the client, releasing any open resources.
func (*Redigo) LRange ¶
LRange gets array range that we set using LPush between index Start and Stop.
func (*Redigo) Publish ¶
Publish sends message to a topic and returns numbers of subscriber that receives the message.
func (*Redigo) SAdd ¶
SAdd add the specified members to the set stored at key. It returns false if key and value combination exists.
func (*Redigo) SetNX ¶
SetNX sets a value to a key with specified timeouts. SetNX returns false if the key exists.
type RedisClientItf ¶
type RedisClientItf interface { // Get gets the value from redis in []byte form. Get(ctx context.Context, key string) ([]byte, error) // SetEX sets the value to a key with timeout in seconds. SetEX(ctx context.Context, key string, seconds int64, value string) error // SetNX sets a value to a key with specified timeouts. // SetNX returns false if the key exists. SetNX(ctx context.Context, key string, seconds int64, value string) (bool, error) // Exists checks whether the key exists in redis. Exists(ctx context.Context, key string) (bool, error) // Expire sets the TTL of a key to specified value in seconds. Expire(ctx context.Context, key string, seconds int64) (bool, error) // TTL gets the time to live of a key / expiry time. TTL(ctx context.Context, key string) (int64, error) // HGet gets the value of a hash field. HGet(ctx context.Context, key, field string) ([]byte, error) // HExists determines if a hash field exists. HExists(ctx context.Context, key, field string) (bool, error) // HSet sets the string value of a hash field. HSet(ctx context.Context, key, field, value string) (bool, error) // Del deletes a key. Del(ctx context.Context, key ...interface{}) (int64, error) // Close closes the client, releasing any open resources. Close() }
RedisClientItf is a client to interact with Redis.
type RedisConfiguration ¶
type RedisConfiguration struct { // IdleConnectionLimit describes maximum idle connection before it closed. IdleConnectionLimit int64 // OpenConnectionLimit describes maximum open connection can be opened. OpenConnectionLimit int64 // WaitOpenConnection describes if operation should wait // for open connection to do operation. WaitOpenConnection bool // Addresses list of available addresses for cluster connection. Addresses []string // Enables read-only commands on slave nodes. ReadOnly bool // Allows routing read-only commands to the closest master or slave node. // It automatically enables ReadOnly. RouteByLatency bool // Allows routing read-only commands to the random master or slave node. // It automatically enables ReadOnly. RouteRandomly bool // MaxRetries describes the maximum retry if command fails. // Too much retry will prevent other command from being executed. MaxRetries int64 // DialTimeout is in seconds. DialTimeout int64 // MaxConnAge is in seconds. MaxConnAge int64 // IdleTimeout is in seconds. IdleTimeout int64 // MinIdleConnection describes the minimum open idle connection to be keep at all time. MinIdleConnection int64 }
RedisConfiguration configuration.
type RedisMigrator ¶
type RedisMigrator struct {
// contains filtered or unexported fields
}
RedisMigrator is a redis client to migrate from one instance to another. All the create commands will be executed to the new instance. All the update and delete commands will be executed on both instances. While the read commands will read from the new instance first, and if the result is not found, it will attempt to read from the old one.
func NewRedisMigrator ¶
func NewRedisMigrator(origin, destination RedisClientItf) (*RedisMigrator, error)
NewRedisMigrator return a redis migrator client.
func (*RedisMigrator) Close ¶
func (r *RedisMigrator) Close()
Close closes the client, releasing any open resources.
func (*RedisMigrator) Del ¶
func (r *RedisMigrator) Del(ctx context.Context, key ...interface{}) (int64, error)
Del deletes a key.
func (*RedisMigrator) SetEX ¶
func (r *RedisMigrator) SetEX( ctx context.Context, key string, seconds int64, value string, ) error
SetEX sets the value to a key with timeout in seconds.
type Ristretto ¶
type Ristretto struct {
// contains filtered or unexported fields
}
Ristretto returns a in-process storage client using ristretto library.
func NewRistretto ¶
func NewRistretto(config *RistrettoConfiguration) (*Ristretto, error)
NewRistretto return a redis client.
func (*Ristretto) Close ¶
func (r *Ristretto) Close()
Close stops all goroutines and closes all channels.
func (*Ristretto) Get ¶
Get returns the value (if any) and a boolean representing whether the value was found or not.
func (*Ristretto) Set ¶
Set attempts to add the key-value item to the cache. If it returns false, then the Set was dropped and the key-value item isn't added to the cache. If it returns true, there's still a chance it could be dropped by the policy if its determined that the key-value item isn't worth keeping, but otherwise the item will be added and other items will be evicted in order to make room.
func (*Ristretto) SetEX ¶
func (r *Ristretto) SetEX( _ context.Context, key string, value interface{}, ttl time.Duration, ) bool
SetEX works like Set but adds a key-value pair to the cache that will expire after the specified TTL (time to live) has passed. A zero value means the value never expires, which is identical to calling Set. A negative value is a no-op and the value is discarded.
type RistrettoClientItf ¶
type RistrettoClientItf interface { // Get returns the value (if any) and a boolean representing whether the value was found or not. Get(ctx context.Context, key string) (res interface{}, exists bool) // Set attempts to add the key-value item to the cache. // If it returns false, then the Set was dropped and the key-value item isn't added to the cache. // If it returns true, there's still a chance it could be dropped by the policy // if its determined that the key-value item isn't worth keeping, // but otherwise the item will be added and other items will be evicted in order to make room. Set(ctx context.Context, key string, value interface{}) bool // SetEX works like Set but adds a key-value pair to the cache // that will expire after the specified TTL (time to live) has passed. // A zero value means the value never expires, which is identical to calling Set. // A negative value is a no-op and the value is discarded. SetEX(ctx context.Context, key string, value interface{}, TTL time.Duration) bool // Del deletes the key-value item from the cache if it exists. Del(ctx context.Context, key string) // Clear empties the cache store and zeroes all policy counters. Clear(ctx context.Context) // Close stops all goroutines and closes all channels. Close() }
RistrettoClientItf is a in-process or local cache storage client.
type RistrettoConfiguration ¶
type RistrettoConfiguration struct { // NumCounters determines the number of counters (keys) to keep that hold // access frequency information. It's generally a good idea to have more // counters than the max cache capacity, as this will improve eviction // accuracy and subsequent hit ratios. // // For example, if you expect your cache to hold 1,000,000 items when full, // NumCounters should be 10,000,000 (10x). Each counter takes up 4 bits, so // keeping 10,000,000 counters would require 5MB of memory. NumCounters int64 // MaxCost can be considered as the cache capacity, in whatever units you // choose to use. // // For example, if you want the cache to have a max capacity of 100MB, you // would set MaxCost to 100,000,000 and pass an item's number of bytes as // the `cost` parameter for calls to Set. If new items are accepted, the // eviction process will take care of making room for the new item and not // overflowing the MaxCost value. MaxCost int64 // BufferItems determines the size of Get buffers. // // Unless you have a rare use case, using `64` as the BufferItems value // results in good performance. BufferItems int64 // Metrics determines whether cache statistics are kept during the cache's // lifetime. There *is* some overhead to keeping statistics, so you should // only set this flag to true when testing or throughput performance isn't a // major factor. Metrics bool }
RistrettoConfiguration configuration.