https://github.com/no-src/gin-session-redis
Gin middleware for session management
https://github.com/no-src/gin-session-redis
Last synced: 3 months ago
JSON representation
Gin middleware for session management
- Host: GitHub
- URL: https://github.com/no-src/gin-session-redis
- Owner: no-src
- License: mit
- Created: 2023-06-06T15:29:03.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T05:16:34.000Z (over 1 year ago)
- Last Synced: 2024-10-21T08:12:25.625Z (over 1 year ago)
- Language: Go
- Size: 56.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gin-session-redis
[](https://github.com/no-src/gin-session-redis/actions)
[](https://github.com/no-src/gin-session-redis/blob/main/LICENSE)
[](https://pkg.go.dev/github.com/no-src/gin-session-redis)
[](https://goreportcard.com/report/github.com/no-src/gin-session-redis)
[](https://codecov.io/gh/no-src/gin-session-redis)
[](https://github.com/no-src/gin-session-redis/releases)
Gin middleware for session management with redis store.
The gin-session-redis project is a fork
of [gin-contrib/sessions/redis](https://github.com/gin-contrib/sessions/tree/master/redis).
The purpose of this fork is to replace the [redigo](https://github.com/gomodule/redigo)
with [go-redis](https://github.com/redis/go-redis) as the driver of redis store.
## Usage
Download and install it:
```bash
go get -u github.com/no-src/gin-session-redis
```
## Example
```go
package main
import (
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github.com/no-src/gin-session-redis/redis"
)
func main() {
r := gin.Default()
store, _ := redis.NewStore(10, "tcp", "localhost:6379", "", []byte("secret"))
r.Use(sessions.Sessions("mysession", store))
r.GET("/incr", func(c *gin.Context) {
session := sessions.Default(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")
}
```