redis

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package redis 实现 SessionStore 接口的 Redis 存储。

合并旧的 session_store + availability_store + session_rotator 三件套: session 按 user_id 索引存入 Redis,可用性标记用独立 key(带 TTL), round-robin 选取在 GetAvailable 内完成。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SessionStore

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

SessionStore 是基于 Redis 的 SessionStore 实现。

维护 round-robin 计数器,从 Redis 列出全部 session 后按可用性过滤、 取模选一个。调用方通过 ReportSuccess/ReportFailure 反馈结果。

func NewSessionStore

func NewSessionStore(rdb *redis.Client) *SessionStore

NewSessionStore 创建 Redis SessionStore。

func (*SessionStore) GetAvailable

func (s *SessionStore) GetAvailable(ctx context.Context, req session.AuthRequirement) (*session.Session, error)

GetAvailable 按登录态需求选取一个可用 session。

round-robin:列出全部 session → 排序保证取模稳定 → 过滤不可用 → 计数器取模。 全部不可用返回 ErrNoAvailableSession。

地基阶段 AuthAnonymous 和 AuthLoggedIn 共用同一 cookie 池(网易云匿名接口用任意 登录态 cookie 即可),后续 AuthRequirement 可驱动不同池。

func (*SessionStore) ListAll

func (s *SessionStore) ListAll(ctx context.Context) ([]string, error)

ListAll 列出全部 session 的 userID(worker 健康检查用)。

用 SCAN 遍历 session key 前缀,提取 userID。

func (*SessionStore) ReportFailure

func (s *SessionStore) ReportFailure(sessionID string, _ error)

ReportFailure 上报 session 调用失败,标记为不可用(带 TTL)。

func (*SessionStore) ReportSuccess

func (s *SessionStore) ReportSuccess(sessionID string)

ReportSuccess 上报 session 调用成功,恢复其可用性标记。

func (*SessionStore) Save

func (s *SessionStore) Save(ctx context.Context, sess *session.Session) error

Save 保存新 session(登录成功后写入 cookie 池)。

Jump to

Keyboard shortcuts

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