onlinestore

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config 在线状态存储配置

type OnlineOption

type OnlineOption func(*redis.ZRangeBy)

OnlineOption 在线用户查询选项

func WithPage

func WithPage(page, pageSize int64) OnlineOption

WithPage 设置分页参数

type Option

type Option func(*Config)

Option 配置选项函数

func WithContext

func WithContext(ctx context.Context) Option

WithContext 设置上下文

func WithKey

func WithKey(key string) Option

WithKey 设置Redis存储键名

func WithMaxPageSize

func WithMaxPageSize(size int64) Option

WithMaxPageSize 设置分页查询的最大页面大小

func WithOnlineTTLSeconds

func WithOnlineTTLSeconds(seconds int64) Option

WithOnlineTTLSeconds 设置在线状态过期时间(秒)

type Store

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

Store 在线状态存储

func New

func New(client *redis.Client, opts ...Option) (*Store, error)

New 创建一个新的在线状态存储实例

func (*Store) CleanupOffline

func (s *Store) CleanupOffline() (int64, error)

CleanupOffline 清理离线用户数据 返回清理的用户数量

func (*Store) EachOnlineUser

func (s *Store) EachOnlineUser(fn func(userId string) error) error

EachOnlineUser 遍历所有在线用户

func (*Store) FilterOnlineUsers

func (s *Store) FilterOnlineUsers(userIDs []string) (map[string]float64, error)

FilterOnlineUsers 从给定的用户ID列表中筛选出在线的用户 返回 map[userId]lastActiveTimestamp

func (*Store) Heartbeat

func (s *Store) Heartbeat(userId string) error

Heartbeat 记录用户心跳,标记用户在线

func (*Store) OnlineCount

func (s *Store) OnlineCount() (int64, error)

OnlineCount 获取当前在线用户数量

func (*Store) OnlineUsers

func (s *Store) OnlineUsers(opts ...OnlineOption) ([]string, error)

OnlineUsers 获取在线用户列表

func (*Store) SetOffline

func (s *Store) SetOffline(userId string) error

SetOffline 设置用户离线

Jump to

Keyboard shortcuts

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