Documentation
¶
Index ¶
Constants ¶
View Source
const (
MsgItemNotFound = "item not found in cache"
)
Variables ¶
View Source
var ( ErrCacheInvalid = errors.New("cache is invalid") ErrItemNotFound = errors.New(MsgItemNotFound) ErrNoSuchIndexFound = errors.New("no such index found in cache") ErrConfigNotSet = errors.New("configuration not initialized") ErrExpirationNotSet = errors.New("no default expiration set and no specific expiration provided") ErrMutexExpirationNotSet = errors.New("no mutex expiration set for multiserver mode") ErrNoClientSet = errors.New("no redis client set in cache") ErrCachingDisabled = errors.New("redis caching is disabled") )
Functions ¶
Types ¶
type RedisCache ¶
type RedisCache interface {
// Initialization
Init(config RedisCacheConfig, refreshFillerFunc func(ctx context.Context) error, refreshInitFunc func(ctx context.Context) error)
// Refreshing and validity
IsValid(ctx context.Context) bool
SetToInvalid(ctx context.Context)
SetToValid(ctx context.Context)
RefreshCacheAsync(ctx context.Context, forceUpdate bool)
// CRUD
Store(ctx context.Context, key string, content interface{}) error
StoreWithExpiration(ctx context.Context, key string, content interface{}, expirationTime *time.Duration) error
Read(ctx context.Context, key string, modelPtr interface{}) error
ReadWithExpiration(ctx context.Context, key string, modelPtr interface{}, expirationTime *time.Duration) error
ReadGroup(ctx context.Context, keys []string, modelArrayPtr interface{}) error
Delete(ctx context.Context, key string) error
// Set handling
AddItemToSet(ctx context.Context, key string, item string) error
IsItemInSet(ctx context.Context, key string, item string) (bool, error)
GetItemsInSetAsMap(ctx context.Context, key string) (map[string]struct{}, error)
DeleteItemFromSet(ctx context.Context, key string, item string) error
// Flag handling
SetFlag(ctx context.Context, key string) error
SetFlagWithExpiration(ctx context.Context, key string, expirationTime *time.Duration) error
GetFlag(ctx context.Context, key string) (bool, error)
DeleteFlag(ctx context.Context, key string) error
// Index handling
CreateIndex(ctx context.Context, index string, options *redis.FTCreateOptions, fieldSchemas []*redis.FieldSchema) (string, error)
SearchInIndex(ctx context.Context, indexName string, queryString string, options *redis.FTSearchOptions, modelArrayPtr interface{}) (totalCount int, err error)
DeleteIndex(ctx context.Context, index string, deleteDocuments bool) error
// Key handling
KeyForAll() string
KeyForOne(id uuid.UUID) string
KeyForCustom(customKey string) string
KeyForValuedCustom(name string, values ...string) string
KeyForNotFound() string
}
func NewRedisCache ¶
func NewRedisCache(redisClient *redis.Client, appName, cacheName string) RedisCache
Click to show internal directories.
Click to hide internal directories.