redistore

package module
v0.0.0-...-205f7fb Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2013 License: MIT Imports: 6 Imported by: 0

README

redistore

A session store backend for gorilla/sessions - src. This is a modified version of boj/redistore in that you pass an existing redis connection rather than allowing redistore to create connections for you.

Requirements

Depends on the Redigo Redis library.

Installation

go get github.com/ahare/redistore

Documentation

Available on godoc.org.

See http://www.gorillatoolkit.org/pkg/sessions for full documentation on underlying interface.

Example
// Fetch new store.
conn := redis.Dial("tcp", ":6379")
store := NewRediStore(conn, []byte("secret-key"))
defer store.Close()

// Get a session.
session, err = store.Get(req, "session-key")
if err != nil {
    log.Error(err.Error())
}

// Add a value.
session.Values["foo"] = "bar"

// Save.
if err = sessions.Save(req, rsp); err != nil {
    t.Fatalf("Error saving session: %v", err)
}

// Delete session.
session.Options.MaxAge = -1
if err = sessions.Save(req, rsp); err != nil {
    t.Fatalf("Error saving session: %v", err)
}

Notes

July 18th, 2013
  • Delete() should be considered deprecated since it is not exposed via the gorilla/sessions interface. Set session.Options.MaxAge = -1 and call Save instead.

Documentation

Overview

Package redistore is a session store backend for gorilla/sessions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RediStore

type RediStore struct {
	Conn    redis.Conn
	Codecs  []securecookie.Codec
	Options *sessions.Options // default configuration
}

RediStore stores sessions in a redis backend.

func NewRediStore

func NewRediStore(conn redis.Conn, keyPairs ...[]byte) *RediStore

NewRediStore returns a new RediStore.

func (*RediStore) Close

func (s *RediStore) Close()

Close cleans up the redis connections.

func (*RediStore) Delete

func (s *RediStore) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Delete removes the session from redis, and sets the cookie to expire.

WARNING: This method should be considered deprecated since it is not exposed via the gorilla/sessions interface. Set session.Options.MaxAge = -1 and call Save instead. - July 18th, 2013

func (*RediStore) Get

func (s *RediStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get returns a session for the given name after adding it to the registry.

See gorilla/sessions FilesystemStore.Get().

func (*RediStore) New

func (s *RediStore) New(r *http.Request, name string) (*sessions.Session, error)

New returns a session for the given name without adding it to the registry.

See gorilla/sessions FilesystemStore.New().

func (*RediStore) Save

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

Save adds a single session to the response.

Jump to

Keyboard shortcuts

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