redis_commands

package module
v0.2.23 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 11 Imported by: 0

README ¶


@ermes-labs/redis-go

Store implementation for the Ermes framework using Redis

Github CI GitHub Latest Release Docker Image

Introduction 📖

Ermes (Edge-to-Cloud Resource Management for Enhanced Session-based applications)

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func NewKeySpace ¶

func NewKeySpace(prefix string) keySpace

Create a new KeySpace from a prefix.

Types ¶

type ErmesKeySpaces ¶

type ErmesKeySpaces struct {
	PublicErmesKeySpaces
	InternalErmesKeySpaces
}

Struct that contains all the key spaces of Ermes.

func NewErmesKeySpaces ¶

func NewErmesKeySpaces(sessionId string) ErmesKeySpaces

Create a ErmesKeySpaces struct.

func NewErmesKeySpacesWithoutSessionSpecificKeySpaces ¶

func NewErmesKeySpacesWithoutSessionSpecificKeySpaces() ErmesKeySpaces

Create a ErmesKeySpaces struct without session specific key spaces.

type InternalErmesKeySpaces ¶

type InternalErmesKeySpaces struct {
	SessionMetadata keySpace
	Config          keySpace
}

Struct that contains all the internal key spaces of Ermes.

func NewInternalErmesKeySpaceWithoutSessionSpecificKeySpaces ¶

func NewInternalErmesKeySpaceWithoutSessionSpecificKeySpaces() InternalErmesKeySpaces

Create a InternalErmesKeySpaces struct without session specific key spaces.

func NewInternalErmesKeySpaces ¶

func NewInternalErmesKeySpaces(sessionId string) InternalErmesKeySpaces

Create a InternalErmesKeySpaces struct.

type OffloadData ¶

type OffloadData struct {
	String map[string]string            `json:"string,omitempty"`
	List   map[string][]string          `json:"list,omitempty"`
	Set    map[string][]string          `json:"set,omitempty"`
	ZSet   map[string][]string          `json:"zset,omitempty"`
	Hash   map[string]map[string]string `json:"hash,omitempty"`
}

type PublicErmesKeySpaces ¶

type PublicErmesKeySpaces struct {
	Session keySpace
	Node    keySpace
}

Struct that contains all the public key spaces of Ermes.

func NewPublicErmesKeySpaceWithoutSessionSpecificKeySpaces ¶

func NewPublicErmesKeySpaceWithoutSessionSpecificKeySpaces() PublicErmesKeySpaces

Create a PublicErmesKeySpaces struct without session specific key spaces.

func NewPublicErmesKeySpaces ¶

func NewPublicErmesKeySpaces(sessionId string) PublicErmesKeySpaces

Create a PublicErmesKeySpaces struct.

type RedisCommands ¶

type RedisCommands struct {
	api.Commands
	// contains filtered or unexported fields
}

RedisCommands is a wrapper around the Redis client.

func NewRedisCommands ¶

func NewRedisCommands(client *redis.Client) *RedisCommands

NewRedisCommands creates a new RedisCommands instance.

func (*RedisCommands) AcquireSession ¶

func (c *RedisCommands) AcquireSession(ctx context.Context, sessionId string, opt api.AcquireSessionOptions) (*api.SessionLocation, error)

Acquires a session. If the session has been offloaded and not acquired it returns the new session sessionLocation, otherwise nil. The options defines how the session is acquired. errors: - ErrSessionNotFound: If no session with the given id is found. - ErrSessionIsOffloading: If the session is offloading and the required permission is read-write.

func (*RedisCommands) BestOffloadTargetNodes ¶

func (c *RedisCommands) BestOffloadTargetNodes(
	ctx context.Context,
	nodeId string,
	sessions map[string]api.SessionInfoForOffloadDecision,
	opt api.BestOffloadTargetsOptions,
) ([][2]string, error)

Return the best offload targets composed by the session id and the node id. The options defines how the sessions are selected. Note that sessions and nodes may appear multiple times in the result, to allow for multiple choices of offload targets. those are not grouped by session id or node id to allow to express the priority of the offload targets.

func (*RedisCommands) BestSessionsToOffload ¶

func (c *RedisCommands) BestSessionsToOffload(
	ctx context.Context,
	opt api.BestOffloadTargetsOptions,
) (sessions map[string]api.SessionInfoForOffloadDecision, err error)

Return the best sessions to offload. This list is composed by the session chosen given the local context of the node (direct or indirect knowledge of the status of the system).

func (*RedisCommands) ConfirmSessionOffload ¶

func (c *RedisCommands) ConfirmSessionOffload(
	ctx context.Context,
	id string,
	newLocation api.SessionLocation,
	opt api.OffloadSessionOptions,

	notifyLastVisitedNode func(context.Context, api.SessionLocation) (bool, error),
) (err error)

Confirms the offload of a session. errors: - ErrSessionNotFound: If no session with the given id is found.

func (*RedisCommands) CreateAndAcquireSession ¶

func (c *RedisCommands) CreateAndAcquireSession(
	ctx context.Context,
	options api.CreateAndAcquireSessionOptions,
) (string, error)

Creates a new session and acquires it. Returns the id of the session.

func (*RedisCommands) CreateSession ¶

func (c *RedisCommands) CreateSession(
	ctx context.Context,
	opt api.CreateSessionOptions,
) (string, error)

Creates a new session and returns the id of the session.

func (*RedisCommands) FindLookupNode ¶

func (c *RedisCommands) FindLookupNode(
	ctx context.Context,
	sessionIds []string,
) (infrastructure.Node, error)

Get the lookup node for a session offloading.

func (*RedisCommands) GarbageCollectSessions ¶

func (c *RedisCommands) GarbageCollectSessions(
	ctx context.Context,
	opt api.GarbageCollectSessionsOptions,
	cursor *string,
) (*string, error)

Garbage collect sessions, the options to define how the sessions are garbage collected. The function accept a cursor to continue the garbage collection from the last cursor, nil to start from the beginning. The function returns the next cursor to continue the garbage collection, or nil if the garbage collection is completed.

func (*RedisCommands) GetChildrenNodesOf ¶

func (c *RedisCommands) GetChildrenNodesOf(
	ctx context.Context,
	nodeId string,
) ([]infrastructure.Node, error)

Get the children nodes of a node.

func (*RedisCommands) GetNodeResourcesUsage ¶

func (c *RedisCommands) GetNodeResourcesUsage(
	ctx context.Context,
	nodeId string,
) (sessions uint, resourcesUsage api.ResourcesUsage, err error)

Get the resources usage of a node.

func (*RedisCommands) GetParentNodeOf ¶

func (c *RedisCommands) GetParentNodeOf(
	ctx context.Context,
	nodeId string,
) (*infrastructure.Node, error)

Get the parent node of a node.

func (*RedisCommands) GetSessionMetadata ¶

func (c *RedisCommands) GetSessionMetadata(
	ctx context.Context,
	sessionId string,
) (api.SessionMetadata, error)

Returns the metadata associated with a session. errors: - ErrSessionNotFound: If no session with the given id is found.

func (*RedisCommands) GetSessionResourcesUsage ¶

func (c *RedisCommands) GetSessionResourcesUsage(
	ctx context.Context,
	sessionId string,
) (resourcesUsage api.ResourcesUsage, err error)

Get the resources usage of a session. errors: - ErrSessionNotFound: If no session with the given id is found.

func (*RedisCommands) LoadInfrastructure ¶

func (c *RedisCommands) LoadInfrastructure(
	ctx context.Context,
	infra infrastructure.Infrastructure,
) (err error)

Load the infrastructure.

func (*RedisCommands) OffloadSession ¶

func (c *RedisCommands) OffloadSession(
	ctx context.Context,
	id string,
	opt api.OffloadSessionOptions,
) (io.ReadCloser, func(), error)

OffloadStart starts the offload of a session. The function returns the io.Reader that allows to read the session data, an optional loader function to fulfill the io.Reader, and an error. The function is thought to be used in scenarios where the session data is huge and streaming is required. The loader function will be run concurrently to the reader process. Errors can flow from the loader function to the reader passing trough the io.Reader, vice-versa the loader should stop if the context is canceled. errors: - ErrSessionNotFound: If no session with the given id is found. - ErrSessionIsOffloading: If the session is already offloading. - ErrUnableToOffloadAcquiredSession: If the session is unable to offload because it is acquired.

func (*RedisCommands) OnloadSession ¶

func (c *RedisCommands) OnloadSession(
	ctx context.Context,
	metadata api.SessionMetadata,
	reader io.Reader,
	opt api.OnloadSessionOptions,
) (string, error)

StartOnload starts the onload of a session and returns the id of the session. errors: - ErrSessionNotFound: If no session with the given id is found. - ErrSessionAlreadyOnloaded: If the session is already onloaded.

func (*RedisCommands) ReleaseSession ¶

func (c *RedisCommands) ReleaseSession(
	ctx context.Context,
	sessionId string,
	opt api.AcquireSessionOptions,
) (*api.SessionLocation, error)

func (*RedisCommands) ResourcesUsageUpdateFromChild ¶

func (c *RedisCommands) ResourcesUsageUpdateFromChild(
	ctx context.Context,
	sessions uint,
	resourcesUsageNodesMap map[string]api.ResourcesUsage,
) (err error)

Get the update from the child nodes.

func (*RedisCommands) ResourcesUsageUpdateToParent ¶

func (c *RedisCommands) ResourcesUsageUpdateToParent(
	ctx context.Context,
) (node infrastructure.Node, sessions uint, resourcesUsageNodesMap map[string]api.ResourcesUsage, err error)

Get the update to send to the parent node.

func (*RedisCommands) ScanOffloadableSessions ¶

func (c *RedisCommands) ScanOffloadableSessions(
	ctx context.Context,
	cursor uint64,
	count int64,
) ([]string, uint64, error)

Returns the offloadable sessions, the function returns the new cursor, the list of session ids and an error. The cursor is used to paginate the results. If the cursor is empty, the function returns the first page of results. errors: - ErrInvalidCursor: If the cursor is invalid. - ErrInvalidCount: If the count is invalid.

func (*RedisCommands) ScanOffloadedSessions ¶

func (c *RedisCommands) ScanOffloadedSessions(
	ctx context.Context,
	cursor uint64,
	count int64,
) (ids []string, newCursor uint64, err error)

Returns the offloaded sessions, the function returns the new cursor, the list of session ids and an error. The cursor is used to paginate the results. If the cursor is empty, the function returns the first page of results. errors: - ErrInvalidCursor: If the cursor is invalid. - ErrInvalidCount: If the count is invalid.

func (*RedisCommands) ScanSessions ¶

func (c *RedisCommands) ScanSessions(
	ctx context.Context,
	cursor uint64,
	count int64,
) ([]string, uint64, error)

Returns the ids of the sessions.

func (*RedisCommands) SetSessionMetadata ¶

func (c *RedisCommands) SetSessionMetadata(
	ctx context.Context,
	sessionId string,
	opt api.SessionMetadataOptions,
) error

SetClientCoordinates sets the coordinates of the client of a session. errors: - ErrSessionNotFound: If no session with the given id is found.

func (*RedisCommands) Set_current_node_key ¶

func (c *RedisCommands) Set_current_node_key(ctx context.Context, nodeId string) error

func (*RedisCommands) UpdateOffloadedSessionLocation ¶

func (c *RedisCommands) UpdateOffloadedSessionLocation(
	ctx context.Context,
	id string,
	newLocation api.SessionLocation,
) (bool, error)

Updates the location of an offloaded session, the function returns true if the client has already been redirected to the new location, while the update is in progress. If true, this node is no more the last visited one, otherwise the node is still the last visited one. errors: - ErrSessionNotFound: If no session with the given id is found. - ErrSessionIsNotOffloaded: If the session is not offloaded.

func (*RedisCommands) UpdateSessionResourcesUsage ¶

func (c *RedisCommands) UpdateSessionResourcesUsage(
	ctx context.Context,
	sessionId string,
	resourcesUsage api.ResourcesUsage,
) (err error)

Update the resources usage of a session, this will also update the resources usage of the node. errors: - ErrSessionNotFound: If no session with the given id is found.

Jump to

Keyboard shortcuts

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