Categorygithub.com/craftions/gin-redis-session
modulepackage
0.0.2
Repository: https://github.com/craftions/gin-redis-session.git
Documentation: pkg.go.dev

# README

Redis Sessions

Gin middleware for Redis session management with multi-backend support. This implementation was forked from gin-contrib/sessions and modified for specific engineering problems. We don't recommend using it in your projects because We don’t offer maintenance and breaking changes can be introduced in the future.

Usage

Start using it

Download and install it:

go get github.com/craftions/gin-redis-session

Import it in your code:

import "github.com/craftions/gin-redis-session"

Basic Examples

Redis

package main

import (
  sessions "github.com/craftions/gin-redis-session"
  "github.com/gin-gonic/gin"
)

func main() {
  r := gin.Default()
  store, _ := redis.NewStore(10, "tcp", "localhost:6379", "", 4096, []byte("secret"))
  r.Use(sessions.Sessions("mysession", store))

  r.GET("/incr", func(c *gin.Context) {
    session := sessions.Default("mysession", c)
    var count int
    v := session.Get("count")
    if v == nil {
      count = 0
    } else {
      count = v.(int)
      count++
    }
    session.Set("count", count)
    session.Save()
    c.JSON(200, gin.H{"count": count})
  })
  r.Run(":8000")
}

# Packages

Package tester is a package to test each packages of session stores, such as cookie, redis, memcached, mongo, memstore.

# Functions

shortcut to get session.
GetRedisStore get the actual woking store.
size: maximum number of idle connections.
NewStoreWithDB - like NewStore but accepts `DB` parameter to select redis DB instead of using the default one ("0") Ref: https://godoc.org/github.com/boj/redistore#NewRediStoreWithDB.
NewStoreWithPool instantiates a RediStore with a *redis.Pool passed in.
No description provided by the author
SetKeyPrefix sets the key prefix in the redis database.

# Constants

No description provided by the author

# Structs

Options stores configuration for a session or session store.

# Interfaces

No description provided by the author
Wraps thinly gorilla-session methods.
No description provided by the author