Documentation
¶
Overview ¶
Redis integration.
Index ¶
- Constants
- func BLPop(rail miso.Rail, timeout time.Duration, key string) ([]string, bool, error)
- func BLPopJson[T any](rail miso.Rail, timeout time.Duration, key string) ([]T, bool, error)
- func BRPop(rail miso.Rail, timeout time.Duration, key string) ([]string, bool, error)
- func BRPopJson[T any](rail miso.Rail, timeout time.Duration, key string) ([]T, bool, error)
- func Decr(rail miso.Rail, key string) (after int64, er error)
- func DecrBy(rail miso.Rail, key string, v int64) (after int64, er error)
- func Eval(rail miso.Rail, script string, keys []string, args ...interface{}) (any, error)
- func Exists(rail miso.Rail, key string) (bool, error)
- func Expire(rail miso.Rail, key string, exp time.Duration) (bool, error)
- func Get(rail miso.Rail, key string) (string, bool, error)
- func GetJson[T any](rail miso.Rail, key string) (T, bool, error)
- func GetRedis() *redis.Client
- func GetStr(key string) (string, error)
- func Incr(rail miso.Rail, key string) (after int64, er error)
- func IncrBy(rail miso.Rail, key string, v int64) (after int64, er error)
- func InitRedis(rail miso.Rail, p RedisConnParam) (*redis.Client, error)
- func InitRedisFromProp(rail miso.Rail) (*redis.Client, error)
- func IsNil(err error) bool
- func IsRLockNotObtainedErr(err error) bool
- func LPop(rail miso.Rail, key string) (string, bool, error)
- func LPopJson[T any](rail miso.Rail, key string) (T, bool, error)
- func LPush(rail miso.Rail, key string, v any) error
- func LPushJson(rail miso.Rail, key string, v any) error
- func NewRQueue[T any](key string) rqueue[T]
- func NewRateLimiter(name string, max int, period time.Duration) *rateLimiter
- func NewTopic[T any](topic string) *rtopic[T]
- func ObtainRLocker() *redislock.Client
- func RLockExec(ec miso.Rail, key string, runnable Runnable, op ...rLockOption) error
- func RLockRun[T any](rail miso.Rail, key string, runnable LRunnable[T], op ...rLockOption) (T, error)
- func RPop(rail miso.Rail, key string) (string, bool, error)
- func RPopJson[T any](rail miso.Rail, key string) (T, bool, error)
- func RPush(rail miso.Rail, key string, v any) error
- func RPushJson(rail miso.Rail, key string, v any) error
- func Scan(rail miso.Rail, pat string, scanLimit int64, f func(key string) error) error
- func Set(rail miso.Rail, key string, val any, exp time.Duration) error
- func SetJson(rail miso.Rail, key string, val any, exp time.Duration) error
- func SetNX(rail miso.Rail, key string, val any, exp time.Duration) (bool, error)
- func SetNXJson(rail miso.Rail, key string, val any, exp time.Duration) (bool, error)
- func WithBackoff(backoff time.Duration) rLockOption
- type GroupCache
- type JsonSerializer
- type LRunnable
- type RCache
- func (r *RCache[T]) Del(rail miso.Rail, key string) error
- func (r *RCache[T]) DelAll(rail miso.Rail) error
- func (r *RCache[T]) Exists(rail miso.Rail, key string) (bool, error)
- func (r *RCache[T]) Get(rail miso.Rail, key string) (T, bool, error)
- func (r *RCache[T]) GetElse(rail miso.Rail, key string, supplier func() (T, bool, error)) (T, bool, error)
- func (r *RCache[T]) GetVal(rail miso.Rail, key string) (T, error)
- func (r *RCache[T]) GetValElse(rail miso.Rail, key string, supplier func() (T, error)) (T, error)
- func (r *RCache[T]) Put(rail miso.Rail, key string, t T) error
- func (r *RCache[T]) RefreshTTL(rail miso.Rail, key string) error
- func (r *RCache[T]) ScanAll(rail miso.Rail, f func(keys []string) error) error
- type RCacheConfig
- type RCacheV2
- func (r *RCacheV2[K, T]) Del(rail miso.Rail, k K) error
- func (r *RCacheV2[K, T]) DelAll(rail miso.Rail) error
- func (r *RCacheV2[K, T]) Exists(rail miso.Rail, k K) (bool, error)
- func (r *RCacheV2[K, T]) Get(rail miso.Rail, k K) (T, bool, error)
- func (r *RCacheV2[K, T]) GetElse(rail miso.Rail, k K, supplier func() (T, bool, error)) (T, bool, error)
- func (r *RCacheV2[K, T]) GetVal(rail miso.Rail, k K) (T, error)
- func (r *RCacheV2[K, T]) GetValElse(rail miso.Rail, k K, supplier func() (T, error)) (T, error)
- func (r *RCacheV2[K, T]) Put(rail miso.Rail, k K, t T) error
- func (r *RCacheV2[K, T]) RefreshTTL(rail miso.Rail, k K) error
- func (r *RCacheV2[K, T]) ScanAll(rail miso.Rail, f func(keys []string) error) error
- type RLock
- type RLockConfig
- type RedisConnParam
- type Runnable
- type Serializer
Constants ¶
const ( // misoconfig-prop: enable Redis client | false PropRedisEnabled = "redis.enabled" // misoconfig-prop: Redis server host | localhost PropRedisAddress = "redis.address" // misoconfig-prop: Redis server port | 6379 PropRedisPort = "redis.port" // misoconfig-prop: username PropRedisUsername = "redis.username" // misoconfig-prop: password PropRedisPassword = "redis.password" // misoconfig-prop: database | 0 PropRedisDatabase = "redis.database" // misoconfig-prop: max connection pool size | `10 * runtime.GOMAXPROCS` or `64` whichever is greater // misoconfig-doc-only PropRedisMaxPoolSize = "redis.max-pool-size" // misoconfig-prop: minimum idle connection counts | 4 PropRedisMinIdleConns = "redis.min-idle-conns" // misoconfig-prop: add timing hook to redis client | true PropRedisWithTimingHook = "redis.with-timing-hook" // misoconfig-prop: slow command log threshold (for timing hook) | 20ms PropRedisSlowLogThreshold = "redis.slow-log-threshold" )
misoconfig-section: Redis Configuration
const (
Nil = redis.Nil
)
Variables ¶
This section is empty.
Functions ¶
func InitRedis ¶
Initialize redis client
If redis client has been initialized, current func call will be ignored
func InitRedisFromProp ¶
Initialize redis client from configuration
If redis client has been initialized, current func call will be ignored.
func IsRLockNotObtainedErr ¶
Check whether the error is 'redislock.ErrNotObtained'
func NewRateLimiter ¶ added in v0.2.0
func RLockExec ¶
Lock and run the runnable using Redis
The maximum time wait for the lock is 1s, retry every 5ms.
May return 'redislock.ErrNotObtained' when it fails to obtain the lock.
func RLockRun ¶
func RLockRun[T any](rail miso.Rail, key string, runnable LRunnable[T], op ...rLockOption) (T, error)
Lock and run the runnable using Redis
The maximum time wait for the lock is 1s, retry every 5ms.
May return 'redislock:ErrNotObtained' when it fails to obtain the lock.
func WithBackoff ¶ added in v0.2.17
Types ¶
type GroupCache ¶ added in v0.4.2
type GroupCache[K comparable, V any] struct { // contains filtered or unexported fields }
func NewGroupCache ¶ added in v0.4.2
func NewGroupCache[K comparable, V any](conf RCacheConfig, cacheName func(k string) string) *GroupCache[K, V]
func (*GroupCache[K, V]) Get ¶ added in v0.4.2
func (g *GroupCache[K, V]) Get(k string) *RCacheV2[K, V]
type JsonSerializer ¶
type JsonSerializer struct {
}
func (JsonSerializer) Deserialize ¶
func (j JsonSerializer) Deserialize(ptr any, v string) error
type RCache ¶
type RCache[T any] struct { ValueSerializer Serializer // serializer / deserializer // contains filtered or unexported fields }
Redis Cache implementation.
RCache internal isn't backed by an actual redis HSet. Cache name is simply the prefix for each key, and each key is stored independently.
Use NewRCache(...) to instantiate.
func NewRCache ¶
func NewRCache[T any](name string, conf RCacheConfig) RCache[T]
Create new RCache
Use NewRCacheV2 for complex key type.
func (*RCache[T]) GetElse ¶ added in v0.2.4
func (r *RCache[T]) GetElse(rail miso.Rail, key string, supplier func() (T, bool, error)) (T, bool, error)
Get from cache else run supplier
func (*RCache[T]) GetValElse ¶ added in v0.2.13
Get from cache else run supplier
func (*RCache[T]) RefreshTTL ¶ added in v0.2.1
type RCacheConfig ¶
type RCacheConfig struct {
//expire time for each entry
Exp time.Duration
// Disable use of distributed lock to synchronize access to the key in the cache.
//
// Most of the operations are atomic except Get(...) with supplier callback.
// If your are loading the cache manually using Put(...), then you probably don't need synchronization at all.
NoSync bool
}
Configuration of RCache.
type RCacheV2 ¶ added in v0.4.2
Redis Cache implementation.
RCache internal isn't backed by an actual redis HSet. Cache name is simply the prefix for each key, and each key is stored independently.
Use [NewRCacheV2] to instantiate.
func NewRCacheV2 ¶ added in v0.2.6
func NewRCacheV2[K any, T any](name string, conf RCacheConfig) *RCacheV2[K, T]
Create new RCache.
K type must either be string or implements fmt.Stringer, if not, it panics.
func (*RCacheV2[K, T]) GetValElse ¶ added in v0.4.2
func (*RCacheV2[K, T]) RefreshTTL ¶ added in v0.4.2
type RLock ¶
type RLock struct {
// contains filtered or unexported fields
}
RLock
func NewCustomRLock ¶
func NewCustomRLock(rail miso.Rail, key string, config RLockConfig) *RLock
Create customized RLock.
func NewRLock ¶
Create new RLock with default backoff configuration (5ms backoff window, 6000 attempts, i.e., retry for 30s).
func NewRLockf ¶
Create new RLock with default backoff configuration (5ms backoff window, 6000 attempts, i.e., retry for 30s).
type RLockConfig ¶
type RLockConfig struct {
// Backoff duration.
//
// This is not an exact configuration. Linear back off strategy is used with a window size of 5ms, which means RLock will attempt to acquire the lock every 5ms.
//
// The number of times we may attempt to acquire the lock is called steps, which is by default 600 (that's 30s = 600 * 5ms).
// When BackoffDuration is provided, this duration is divided by 5ms to convert to steps and then used by RLock.
BackoffDuration time.Duration
}
RLock Configuration.