memorypresence

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package memorypresence contains the shared in-memory presence implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	SessionID   string    // session 唯一标识
	IdentityID  string    // 认证身份 ID
	TenantID    string    // 租户 ID
	NodeID      string    // 所属节点 ID
	RemoteAddr  string    // 客户端远端地址
	ConnectedAt time.Time // 连接建立时间(UTC)
	ExpiresAt   time.Time // 快照过期时间,零值表示不过期
}

Info is an online session snapshot stored by Presence. Info 是在线 session 的快照数据,用于 Presence 层存储和查询。

type Presence

type Presence struct {
	// contains filtered or unexported fields
}

Presence stores online session snapshots in memory. Presence 基于内存的在线状态索引,维护 session 和 identity 两级映射。

func New

func New() *Presence

New creates an empty in-memory presence index. New 创建一个空的内存在线状态索引。

func (*Presence) GetIdentitySessions

func (p *Presence) GetIdentitySessions(ctx context.Context, tenantID, identityID string) ([]Info, error)

GetIdentitySessions returns unexpired session snapshots for an identity. GetIdentitySessions 返回指定身份的未过期 session 快照列表。

func (*Presence) IsOnline

func (p *Presence) IsOnline(ctx context.Context, tenantID, identityID string) (bool, error)

IsOnline reports whether identity has at least one unexpired session. IsOnline 判断指定身份是否至少有一个未过期的在线 session。

func (*Presence) Register

func (p *Presence) Register(ctx context.Context, session *Info) error

Register stores or refreshes a session snapshot. Register 注册或刷新 session 在线快照,同时维护 identity 索引。

func (*Presence) Unregister

func (p *Presence) Unregister(ctx context.Context, sessionID string) error

Unregister removes a session snapshot. Unregister 移除指定 session 的在线快照,同时清理空的 identity 索引。

Jump to

Keyboard shortcuts

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