redis

package
v0.0.0-...-a4dd944 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package redis contains middleware that depends on github.com/garyburd/redigo/redis

Index

Constants

View Source
const (
	DEFAULT_SESSION_TIMEOUT = 30 * 24 * 60 * 60
)

Variables

This section is empty.

Functions

func BuildRedis

func BuildRedis(redisAddr string) func(c *web.C, h http.Handler) http.Handler

A middleware that ensures a redis connection is present in c.Env["redis"]. The connection is built from a redigo Pool.

func BuildThrottleMiddleWare

func BuildThrottleMiddleWare(interval int, keyfunc Keyfunc) func(c *web.C, h http.Handler) http.Handler

Throttling middleware using redis.

Parameters

interval - throttling interval in seconds
keyfunc - function that looks at the current request and returns an appropriate throttle key and limit

Assumes redis connection is in c.Env["redis"] - see BuildRedis()

Example

  	m := web.New()
	m.Use(middleware.EnvInit)
	m.Use(redis.BuildRedis(config.RedisAddr))
	m.Use(IdentifyServiceMiddleware)
	m.Use(redis.BuildThrottleMiddleWare(3600, func(c *web.C, r *http.Request) (string, int) {
		service_id := c.Env["service_id"].(int)
		return fmt.Sprintf("api:throttle:%d", service_id), 1000
	}))

func NewSessionHolder

func NewSessionHolder() base.SessionHolder

NewSessionHolder creates a new redis-backed gob-encoded session holder

Types

type Keyfunc

type Keyfunc func(c *web.C, r *http.Request) (string, int)

type SessionHolder

type SessionHolder struct {
	base.BaseSessionHolder
}

SessionHolder is a redis-backed session store that gob-encodes sessions.

It requires a redigo redis connection set up in c.Env["redis"]. You can use BuildRedis() to create middleware that does this

func (*SessionHolder) Destroy

func (sh *SessionHolder) Destroy(c web.C, session *base.Session) error

Destroy deletes a session from redis

func (*SessionHolder) Get

func (sh *SessionHolder) Get(c web.C, r *http.Request) (*base.Session, error)

Get the session for this request from Redis

func (*SessionHolder) RegenerateId

func (sh *SessionHolder) RegenerateId(c web.C, session *base.Session) (string, error)

func (*SessionHolder) ResetTTL

func (sh *SessionHolder) ResetTTL(c web.C, session *base.Session) error

func (*SessionHolder) Save

func (sh *SessionHolder) Save(c web.C, session *base.Session) error

Save a session to redis

Jump to

Keyboard shortcuts

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