redis

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package redis provides a Redis-based session provider implementation for the gone HTTP session management system.

Index

Constants

View Source
const SessionTypeRedis httpsession.SessionType = "REDIS"

SessionTypeRedis defines the session type identifier for Redis sessions

Variables

View Source
var (
	// SessionPrefix defines the default prefix for Redis session keys
	SessionPrefix = "httpsession"
)

Functions

This section is empty.

Types

type SessionProvider

type SessionProvider struct {
	Master datastore.RedisOperator // Master Redis instance for write operations
	Slave  datastore.RedisOperator // Slave Redis instance for read operations
}

SessionProvider implements the httpsession.SessionProvider interface using Redis as the backend storage. It supports both master and slave Redis instances for read/write separation.

func NewSessionProvider

func NewSessionProvider(profileName string) *SessionProvider

NewSessionProvider creates a new SessionProvider using a Redis profile name. It initializes both master and slave Redis connections based on the profile configuration.

func NewSessionProviderWithRedis

func NewSessionProviderWithRedis(redis *datastore.Redis) *SessionProvider

NewSessionProviderWithRedis creates a new SessionProvider using an existing Redis instance. It extracts both master and slave connections from the provided Redis instance.

func (*SessionProvider) Delete

func (s *SessionProvider) Delete(key string)

Delete removes a session from Redis storage by its key. It prefers the master instance for write operations, falling back to slave if master is unavailable. No action is taken if no Redis instance is available.

func (*SessionProvider) NewSession

func (s *SessionProvider) NewSession(expire time.Time) httpsession.Session

NewSession creates a new session with the specified expiration time

func (*SessionProvider) Save

func (s *SessionProvider) Save(session httpsession.Session) error

Save persists a session to Redis storage with expiration time. It prefers the master instance for write operations, falling back to slave if master is unavailable. Returns an error if no Redis instance is available, session is nil, or session has expired.

func (*SessionProvider) Session

func (s *SessionProvider) Session(key string) httpsession.Session

Session retrieves a specific session by its key from Redis storage. It prefers the slave instance for read operations, falling back to master if slave is unavailable. Returns nil if the session is not found or if no Redis instance is available.

func (*SessionProvider) Sessions

func (s *SessionProvider) Sessions() map[string]httpsession.Session

Sessions retrieves all active sessions from Redis storage. It prefers the slave instance for read operations, falling back to master if slave is unavailable. Returns an empty map if no Redis instance is available.

func (*SessionProvider) Type added in v1.0.3

Type returns the session type identifier for this provider

Jump to

Keyboard shortcuts

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