redis

package
v0.0.0-...-77f0b0c Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const CacheKeyHubspotCompanies = "hubspot-companies"
View Source
const CacheKeySessionsToProcess = "sessions-to-process"
View Source
const LockPollInterval = 100 * time.Millisecond

Variables

View Source
var (
	ServerAddr = env.Config.RedisEndpoint
)

Functions

func BillingQuotaExceededKey

func BillingQuotaExceededKey(projectId int, productType model.PricingProductType) string

func CachedEval

func CachedEval[T any](ctx context.Context, redis *Client, cacheKey string, lockTimeout, cacheExpiration time.Duration, fn func() (*T, error), opts ...Option) (value *T, err error)

CachedEval will return the value at cacheKey if it exists. If it does not exist or is nil, CachedEval calls `fn()` to evaluate the result, and stores it at the cache key.

func EventsKey

func EventsKey(sessionId int) string

func GetKey

func GetKey(sessionId int, payloadType model.RawPayloadType) string

func GetSubscriptionDetailsKey

func GetSubscriptionDetailsKey(workspaceID int) string

func GitHubFileErrorKey

func GitHubFileErrorKey(gitHubRepo string, version string, fileName string) string

func GithubRateLimitKey

func GithubRateLimitKey(gitHubRepo string) string

func LastLogTimestampKey

func LastLogTimestampKey(projectId int) string

func NetworkResourcesKey

func NetworkResourcesKey(sessionId int) string

func ServiceGithubErrorCountKey

func ServiceGithubErrorCountKey(serviceId int) string

func SessionInitializedKey

func SessionInitializedKey(sessionSecureId string) string

func WebSocketEventsKey

func WebSocketEventsKey(sessionId int) string

Types

type Client

type Client struct {
	Client  redis.Cmdable
	Cache   *cache.Cache
	Redsync *redsync.Redsync
}

func NewClient

func NewClient() *Client

func (*Client) AcquireLock

func (r *Client) AcquireLock(_ context.Context, key string, timeout time.Duration) (*redsync.Mutex, error)

func (*Client) AddPayload

func (r *Client) AddPayload(ctx context.Context, sessionID int, score float64, payloadType model.RawPayloadType, payload []byte) (int, error)

func (*Client) AddSessionToProcess

func (r *Client) AddSessionToProcess(ctx context.Context, sessionId int, delaySeconds int) error

Adds a session to be processed `delaySeconds` in the future

func (*Client) Del

func (r *Client) Del(ctx context.Context, key string) error

func (*Client) FlushDB

func (r *Client) FlushDB(ctx context.Context) error

func (*Client) GetCustomerBillingInvalid

func (r *Client) GetCustomerBillingInvalid(ctx context.Context, stripeCustomerID string) (bool, error)

func (*Client) GetCustomerBillingWarning

func (r *Client) GetCustomerBillingWarning(ctx context.Context, stripeCustomerID string) (time.Time, error)

func (*Client) GetEventObjects

func (r *Client) GetEventObjects(ctx context.Context, s *model.Session, cursor model.EventsCursor, events map[int]string) ([]model.EventsObject, error, *model.EventsCursor)

func (*Client) GetEvents

func (r *Client) GetEvents(ctx context.Context, s *model.Session, cursor model.EventsCursor, events map[int]string) ([]interface{}, error, *model.EventsCursor)

func (*Client) GetGitHubFileError

func (r *Client) GetGitHubFileError(ctx context.Context, repo string, version string, fileName string) (bool, error)

func (*Client) GetGithubRateLimitExceeded

func (r *Client) GetGithubRateLimitExceeded(ctx context.Context, gitHubRepo string) (bool, error)

func (*Client) GetHubspotCompanies

func (r *Client) GetHubspotCompanies(ctx context.Context, companies interface{}) (err error)

func (*Client) GetRawZRange

func (r *Client) GetRawZRange(ctx context.Context, sessionId int, nextPayloadId *int, payloadType model.RawPayloadType) ([]redis.Z, error)

func (*Client) GetResources

func (r *Client) GetResources(ctx context.Context, s *model.Session, resources map[int]string) ([]interface{}, error)

func (*Client) GetSessionData

func (r *Client) GetSessionData(ctx context.Context, sessionId int, payloadType model.RawPayloadType, objects map[int]string) ([]string, error)

func (*Client) GetSessionsToProcess

func (r *Client) GetSessionsToProcess(ctx context.Context, lockPeriod int, limit int) ([]int64, error)

Retrieves up to `limit` sessions to process. Sets the processing time for each to `lockPeriod` minutes after the current time, so they can be retried in case processing fails.

func (*Client) IncrementServiceErrorCount

func (r *Client) IncrementServiceErrorCount(ctx context.Context, projectId int) (int64, error)

func (*Client) IsBillingQuotaExceeded

func (r *Client) IsBillingQuotaExceeded(ctx context.Context, projectId int, productType model.PricingProductType) (*bool, error)

func (*Client) IsPendingSession

func (r *Client) IsPendingSession(ctx context.Context, sessionSecureId string) (bool, error)

func (*Client) RemoveSessionToProcess

func (r *Client) RemoveSessionToProcess(ctx context.Context, sessionId int) error

Removes a session after processing (successfully or with errors) Only removes the session if its processing time is from a 'lock', in case more events were added after it started processing.

func (*Client) RemoveValues

func (r *Client) RemoveValues(ctx context.Context, sessionId int, payloadType model.RawPayloadType, valuesToRemove []interface{}) error

func (*Client) ResetServiceErrorCount

func (r *Client) ResetServiceErrorCount(ctx context.Context, projectId int) (int64, error)

func (*Client) SetBillingQuotaExceeded

func (r *Client) SetBillingQuotaExceeded(ctx context.Context, projectId int, productType model.PricingProductType, exceeded bool) error

func (*Client) SetCustomerBillingInvalid

func (r *Client) SetCustomerBillingInvalid(ctx context.Context, stripeCustomerID string, value bool) error

func (*Client) SetCustomerBillingWarning

func (r *Client) SetCustomerBillingWarning(ctx context.Context, stripeCustomerID string, value time.Time) error

func (*Client) SetGitHubFileError

func (r *Client) SetGitHubFileError(ctx context.Context, gitHubRepo string, version string, fileName string) error

func (*Client) SetGithubRateLimitExceeded

func (r *Client) SetGithubRateLimitExceeded(ctx context.Context, gitHubRepo string, expirationTime time.Time) error

func (*Client) SetHubspotCompanies

func (r *Client) SetHubspotCompanies(ctx context.Context, companies interface{}) error

func (*Client) SetIsPendingSession

func (r *Client) SetIsPendingSession(ctx context.Context, sessionSecureId string, initialized bool) error

func (*Client) TTL

func (r *Client) TTL(ctx context.Context, key string) time.Duration

type Config

type Config struct {
	BypassCache bool
	IgnoreError bool
	StoreNil    bool
}

type Option

type Option func(cfg *Config)

func WithBypassCache

func WithBypassCache(bypass bool) Option

func WithIgnoreError

func WithIgnoreError(ignoreError bool) Option

func WithStoreNil

func WithStoreNil(storeNil bool) Option

Jump to

Keyboard shortcuts

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