redisstore

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: MIT Imports: 10 Imported by: 2

README

redisstore

GoDoc Build Status Coverage Status Go Report Card

A session store backend for gorilla/sessions - src.

Features

  • Support Redis Sentinel, Cluster, Standalone
  • Support secure cookie
  • Support json, gob serializer or custom serializer
  • Support MaxLength, KeyPrefix and KeyGenFunc options

Installation

    go get github.com/boxgo/redisstore

Requirements

Depends on the go-redis/redis Redis library.

Example
client := redis.NewUniversalClient(&redis.UniversalOptions{
    Addrs: []string{"localhost:6379"},
    DB:    0,
})

store, err := NewStoreWithUniversalClient(client,
    WithKeyPairs([]byte("test")),
    WithKeyPrefix("session_"),
    WithSerializer(&serializer.JSONSerializer{}),
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomKey

func GenerateRandomKey(r *http.Request) (string, error)

Types

type KeyGenFunc

type KeyGenFunc func(*http.Request) (string, error)

type Option

type Option func(ops *Options)

func WithKeyGenFunc

func WithKeyGenFunc(fn KeyGenFunc) Option

func WithKeyPairs

func WithKeyPairs(keyPairs ...[]byte) Option

func WithKeyPrefix

func WithKeyPrefix(keyPrefix string) Option

func WithMaxLength

func WithMaxLength(maxLen int) Option

func WithOptions

func WithOptions(opts *sessions.Options) Option

func WithSerializer

func WithSerializer(serializer serializer.SessionSerializer) Option

type Options

type Options struct {
	Codecs     []securecookie.Codec
	Options    *sessions.Options
	MaxLength  int
	KeyPrefix  string
	KeyGenFunc KeyGenFunc
	Serializer serializer.SessionSerializer
}

type RedisStore

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

func NewStoreWithUniversalClient

func NewStoreWithUniversalClient(client redis.UniversalClient, optFns ...Option) (*RedisStore, error)

func (*RedisStore) Get

func (st *RedisStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get should return a cached session.

func (*RedisStore) New

func (st *RedisStore) New(r *http.Request, name string) (*sessions.Session, error)

New should create and return a new session.

Note that New should never return a nil session, even in the case of an error if using the Registry infrastructure to cache the session.

func (*RedisStore) Save

func (st *RedisStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save should persist session to the underlying store implementation.

func (*RedisStore) SetOptions

func (st *RedisStore) SetOptions(opts *sessions.Options)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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