redis

package
v0.0.0-...-d841f61 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeriodicalLockKey     = "pbehavior-periodical-lock-key"
	RecomputeLockKey      = "pbehavior-recompute-lock-key"
	RecomputeLockDuration = 10 * time.Second

	DelayedScenarioKey   = "delayed-scenario"
	ScenarioExecutionKey = "scenario-execution"
)
View Source
const (
	CacheAlarm = iota
	CacheEntity
	CacheService

	LockStorage
	QueueStorage
	CacheQueue
	AxePeriodicalLockStorage
	RuleTotalEntitiesStorage
	AlarmGroupStorage
	CorrelationLockStorage
	EngineRunInfo
	PBehaviorLockStorage
	ActionScenarioStorage
	EntityServiceStorage
	EngineLockStorage
)

Cache<Type> gives you constants to use for different caches.

View Source
const (
	EnvURL = "CPS_REDIS_URL"
)

Env vars for redis session

View Source
const PbehaviorKey = "pbehaviors"

Variables

This section is empty.

Functions

func IsConnectionError

func IsConnectionError(err error) bool

func NewFailoverOptions

func NewFailoverOptions(sURL string, db int, logger zerolog.Logger,
	reconnectCount int, minReconnectTimeout time.Duration) (*redis.FailoverOptions, error)

NewFailoverOptions handles redis.FailoverOptions creation based on the provided url, which must be on the following shape:

redis-sentinel://[password@]host1[:port1][,host2[:port2]][,hostN[:portN]][/database][?

[timeout=timeout[d|h|m|s|ms|us|ns]][&sentinelMasterId=sentinelMasterId]]

As well supported password parameter same as in NewOptions():

redis://[nouser:password@]host:port/int

With this form "nouser" is ignored, and "password" extracted only.

func NewOptions

func NewOptions(surl string, db int, logger zerolog.Logger,
	reconnectCount int, minReconnectTimeout time.Duration) (*redis.Options, error)

NewOptions handles redis.Options creation based on the surl, which must be on the following shape:

redis://[nouser:password@]host:port/int int must be un number indicating the database

If you have a password for the database, no user is required. But it is required to not leave the user empty to avoid url parsing error.

func NewSession

func NewSession(ctx context.Context, db int, logger zerolog.Logger, reconnectCount int, minReconnectTimeout time.Duration) (*redis.Client, error)

NewSession creates a new connection to a Redis database. Configuration is base on EnvCpsRedisUrl.

Types

type Lock

type Lock interface {
	Key() string
	Token() string
	TTL(ctx context.Context) (time.Duration, error)
	Refresh(ctx context.Context, ttl time.Duration, opt *redislock.Options) error
	Release(ctx context.Context) error
}

type LockClient

type LockClient interface {
	Obtain(ctx context.Context, key string, ttl time.Duration, opt *redislock.Options) (Lock, error)
}

func NewLockClient

func NewLockClient(redisClient redislock.RedisClient) LockClient

type Store

type Store interface {
	// Save prepares value and saves the result to redis.
	Save(ctx context.Context, v interface{}) error
	// Restore gets data from redis and stores the result
	// in the value pointed to by v.
	Restore(ctx context.Context, v interface{}) (bool, error)
}

Store interface is used to implement baseStore any variable to redis. Basic implementation marshals data to json before stores it to cache.

func NewStore

func NewStore(client redis.Cmdable, key string, expiration time.Duration) Store

NewStore creates new store.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL