Documentation
¶
Index ¶
- Constants
- func GetRedis() *redis.Client
- func GetStr(key string) (string, 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 NewRCacheV2[K any, T any](name string, conf RCacheConfig) *rcacheV2[K, 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) error
- func RLockRun[T any](rail miso.Rail, key string, runnable LRunnable[T]) (T, error)
- 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
- type RCacheConfig
- 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-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.
This func looks for following prop:
"redis.address" "redis.port" "redis.username" "redis.password" "redis.database"
func IsRLockNotObtainedErr ¶
Check whether the error is 'redislock.ErrNotObtained'
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 NewRateLimiter ¶ added in v0.2.0
Types ¶
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
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 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).
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.