Documentation
¶
Index ¶
- Constants
- Variables
- func NewComprsser(opts CompressorOptions) *compressor
- func NewLZ4Compressor(minCompressLength int) *compressor
- func NewMultilevelCache(opts ...MultilevelCacheOption) *lruttl.L2Cache
- func NewSnappyCompressor(minCompressLength int) *compressor
- func NewZSTDCompressor(minCompressLength int) *compressor
- type CompressorOptions
- type Done
- type MultilevelCacheOption
- func MultilevelCacheLRUSizeOption(size int) MultilevelCacheOption
- func MultilevelCacheMarshalOption(fn lruttl.L2CacheMarshal) MultilevelCacheOption
- func MultilevelCachePrefixOption(prefix string) MultilevelCacheOption
- func MultilevelCacheRedisOption(c *RedisCache) MultilevelCacheOption
- func MultilevelCacheTTLOption(ttl time.Duration) MultilevelCacheOption
- func MultilevelCacheUnmarshalOption(fn lruttl.L2CacheUnmarshal) MultilevelCacheOption
- type RedisCache
- func NewCompressRedisCache(c redis.UniversalClient, compressMinLength int, opts ...RedisCacheOption) *RedisCache
- func NewLZ4RedisCache(c redis.UniversalClient, compressMinLength int, opts ...RedisCacheOption) *RedisCache
- func NewRedisCache(c redis.UniversalClient, opts ...RedisCacheOption) *RedisCache
- func NewSnappyRedisCache(c redis.UniversalClient, compressMinLength int, opts ...RedisCacheOption) *RedisCache
- func NewZSTDRedisCache(c redis.UniversalClient, compressMinLength int, opts ...RedisCacheOption) *RedisCache
- func (c *RedisCache) Del(ctx context.Context, key string) (int64, error)
- func (c *RedisCache) Get(ctx context.Context, key string) ([]byte, error)
- func (c *RedisCache) GetAndDel(ctx context.Context, key string) ([]byte, error)
- func (c *RedisCache) GetIgnoreNilErr(ctx context.Context, key string) ([]byte, error)
- func (c *RedisCache) GetStruct(ctx context.Context, key string, value interface{}) error
- func (c *RedisCache) GetStructAndTTL(ctx context.Context, key string, value interface{}) (time.Duration, error)
- func (c *RedisCache) GetStructWithDone(ctx context.Context, key string, value interface{}) (Done, error)
- func (c *RedisCache) IncWith(ctx context.Context, key string, value int64, ttl ...time.Duration) (int64, error)
- func (c *RedisCache) Lock(ctx context.Context, key string, ttl ...time.Duration) (bool, error)
- func (c *RedisCache) LockWithDone(ctx context.Context, key string, ttl ...time.Duration) (bool, Done, error)
- func (c *RedisCache) Set(ctx context.Context, key string, value interface{}, ttl ...time.Duration) error
- func (c *RedisCache) SetStruct(ctx context.Context, key string, value interface{}, ttl ...time.Duration) error
- func (c *RedisCache) SetStructWithTTL(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (c *RedisCache) TTL(ctx context.Context, key string) (time.Duration, error)
- type RedisCacheOption
- type RedisSession
Constants ¶
const ( // CompressNone compress none CompressNone byte = iota // Compressed compress Compressed )
Variables ¶
var ErrKeyIsNil = errors.New("key is nil")
Functions ¶
func NewComprsser ¶ added in v0.2.0
func NewComprsser(opts CompressorOptions) *compressor
NewComprsser returns a new compressor
func NewLZ4Compressor ¶ added in v1.4.0
func NewLZ4Compressor(minCompressLength int) *compressor
NewLZ4Compressor returns a new lz4 compressor
func NewMultilevelCache ¶
func NewMultilevelCache(opts ...MultilevelCacheOption) *lruttl.L2Cache
NewMultilevelCache returns a new multilevel cache, it will panic if Cache is nil or TTL is < one second
func NewSnappyCompressor ¶ added in v0.2.0
func NewSnappyCompressor(minCompressLength int) *compressor
NewSnappyCompressor returns a new snappy compressor
func NewZSTDCompressor ¶ added in v1.3.0
func NewZSTDCompressor(minCompressLength int) *compressor
NewZSTDCompressor returns a new zstd compressor
Types ¶
type CompressorOptions ¶ added in v0.2.0
type CompressorOptions struct { // MinCompressLength is the min length to compress MinCompressLength int // Encode compress encode function Encode func([]byte) ([]byte, error) // Decode compress decode function Decode func([]byte) ([]byte, error) // Marshal marshal function Marshal func(v interface{}) ([]byte, error) // Unmarshal unmarshal function Unmarshal func(data []byte, v interface{}) error }
type MultilevelCacheOption ¶ added in v0.2.1
type MultilevelCacheOption func(opt *multilevelCacheOptions)
func MultilevelCacheLRUSizeOption ¶ added in v0.2.1
func MultilevelCacheLRUSizeOption(size int) MultilevelCacheOption
MultilevelCacheLRUSizeOption sets lru size option
func MultilevelCacheMarshalOption ¶ added in v1.1.0
func MultilevelCacheMarshalOption(fn lruttl.L2CacheMarshal) MultilevelCacheOption
MultilevelCacheMarshalOption sets marshal function option
func MultilevelCachePrefixOption ¶ added in v0.2.1
func MultilevelCachePrefixOption(prefix string) MultilevelCacheOption
MultilevelCachePrefixOption sets prefix option
func MultilevelCacheRedisOption ¶ added in v0.2.1
func MultilevelCacheRedisOption(c *RedisCache) MultilevelCacheOption
MultilevelCacheRedisOption sets redis option
func MultilevelCacheTTLOption ¶ added in v0.2.1
func MultilevelCacheTTLOption(ttl time.Duration) MultilevelCacheOption
MultilevelCacheTTLOption sets ttl option
func MultilevelCacheUnmarshalOption ¶ added in v1.1.0
func MultilevelCacheUnmarshalOption(fn lruttl.L2CacheUnmarshal) MultilevelCacheOption
MultilevelCacheUnmarshalOption sets unmarshal function option
type RedisCache ¶ added in v0.0.2
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache redis cache
func NewCompressRedisCache ¶ added in v0.3.2
func NewCompressRedisCache(c redis.UniversalClient, compressMinLength int, opts ...RedisCacheOption) *RedisCache
NewCompressRedisCache the same as NewSnappyRedisCache
func NewLZ4RedisCache ¶ added in v1.4.1
func NewLZ4RedisCache(c redis.UniversalClient, compressMinLength int, opts ...RedisCacheOption) *RedisCache
NewLZ4RedisCache returns a redis cache with lz4 compressor
func NewRedisCache ¶
func NewRedisCache(c redis.UniversalClient, opts ...RedisCacheOption) *RedisCache
NewRedisCache returns a new redis cache
func NewSnappyRedisCache ¶ added in v1.3.0
func NewSnappyRedisCache(c redis.UniversalClient, compressMinLength int, opts ...RedisCacheOption) *RedisCache
NewSnappyRedisCache returns a redis cache with snappy compressor
func NewZSTDRedisCache ¶ added in v1.3.0
func NewZSTDRedisCache(c redis.UniversalClient, compressMinLength int, opts ...RedisCacheOption) *RedisCache
NewZSTDRedisCache returns a redis cache with zstd compressor
func (*RedisCache) GetIgnoreNilErr ¶ added in v0.0.2
GetIgnoreNilErr gets value from cache and ignore nil err
func (*RedisCache) GetStruct ¶ added in v0.0.2
func (c *RedisCache) GetStruct(ctx context.Context, key string, value interface{}) error
GetStruct gets cache and unmarshal to struct
func (*RedisCache) GetStructAndTTL ¶ added in v1.5.0
func (c *RedisCache) GetStructAndTTL(ctx context.Context, key string, value interface{}) (time.Duration, error)
GetStructAndTTL gets cache, unmarshal to struct and return the ttl of it. The cache should be set by SetStructWithTTL
func (*RedisCache) GetStructWithDone ¶ added in v0.2.0
func (c *RedisCache) GetStructWithDone(ctx context.Context, key string, value interface{}) (Done, error)
GetStructWithDone gets data from redis and unmarshal to struct, it returns a done function to delete the data.
func (*RedisCache) IncWith ¶ added in v0.0.2
func (c *RedisCache) IncWith(ctx context.Context, key string, value int64, ttl ...time.Duration) (int64, error)
IncWith inc the value of key from cache
func (*RedisCache) LockWithDone ¶ added in v0.0.2
func (c *RedisCache) LockWithDone(ctx context.Context, key string, ttl ...time.Duration) (bool, Done, error)
LockWithDone locks the key for ttl and return done function to delete the lock
func (*RedisCache) Set ¶ added in v0.0.2
func (c *RedisCache) Set(ctx context.Context, key string, value interface{}, ttl ...time.Duration) error
Set sets data to cache, if ttl is not nil, it will use default ttl
func (*RedisCache) SetStruct ¶ added in v0.0.2
func (c *RedisCache) SetStruct(ctx context.Context, key string, value interface{}, ttl ...time.Duration) error
SetStruct marshals struct to bytes and sets to cache, if it will use default ttl if ttl is nil
func (*RedisCache) SetStructWithTTL ¶ added in v1.5.0
func (c *RedisCache) SetStructWithTTL(ctx context.Context, key string, value interface{}, ttl time.Duration) error
SetStructWithTTL adds expiredAt field to data, marshals data to bytes and sets to cache
type RedisCacheOption ¶ added in v0.2.0
type RedisCacheOption func(c *RedisCache)
RedisCacheOption redis cache option
func RedisCacheMarshalOption ¶ added in v0.2.0
func RedisCacheMarshalOption(fn func(v interface{}) ([]byte, error)) RedisCacheOption
RedisCacheMarshalOption redis cache marshal option
func RedisCachePrefixOption ¶ added in v0.2.0
func RedisCachePrefixOption(prefix string) RedisCacheOption
RedisCachePrefixOption redis cache prefix option
func RedisCacheTTLOption ¶ added in v0.2.0
func RedisCacheTTLOption(ttl time.Duration) RedisCacheOption
RedisCacheTTLOption redis cache ttl option
func RedisCacheUnmarshalOption ¶ added in v0.2.0
func RedisCacheUnmarshalOption(fn func(data []byte, v interface{}) error) RedisCacheOption
RedisCacheUnmarshalOption redis cache unmarshal option
type RedisSession ¶ added in v0.0.2
type RedisSession struct {
// contains filtered or unexported fields
}
func NewRedisSession ¶
func NewRedisSession(c redis.UniversalClient) *RedisSession
NewRedisSession returns a new redis session
func (*RedisSession) Destroy ¶ added in v0.0.2
func (rs *RedisSession) Destroy(ctx context.Context, key string) error
Destroy session from redis
func (*RedisSession) Get ¶ added in v0.0.2
Get session from redis, it will not return error if data is not exists
func (*RedisSession) SetPrefix ¶ added in v0.0.2
func (rs *RedisSession) SetPrefix(prefix string)
SetPrefix sets prefix for redis session's key