https://github.com/go-session/redis
A redis-based session store.
https://github.com/go-session/redis
go-redis-session redis-session
Last synced: 5 months ago
JSON representation
A redis-based session store.
- Host: GitHub
- URL: https://github.com/go-session/redis
- Owner: go-session
- License: mit
- Created: 2018-04-24T02:37:16.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-30T03:34:35.000Z (over 1 year ago)
- Last Synced: 2025-08-13T18:40:29.662Z (12 months ago)
- Topics: go-redis-session, redis-session
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 33
- Watchers: 1
- Forks: 16
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Redis store for [Session](https://github.com/go-session/session)
[![Build][build-status-image]][build-status-url] [![Codecov][codecov-image]][codecov-url] [![ReportCard][reportcard-image]][reportcard-url] [![GoDoc][godoc-image]][godoc-url] [![License][license-image]][license-url]
## Quick Start
### Download and install
```bash
go get -v github.com/go-session/redis/v3
```
### Create file `server.go`
```go
package main
import (
"context"
"fmt"
"net/http"
"github.com/go-session/redis/v3"
"github.com/go-session/session/v3"
)
func main() {
session.InitManager(
session.SetStore(redis.NewRedisStore(&redis.Options{
Addr: "127.0.0.1:6379",
DB: 15,
})),
)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
store, err := session.Start(context.Background(), w, r)
if err != nil {
fmt.Fprint(w, err)
return
}
store.Set("foo", "bar")
err = store.Save()
if err != nil {
fmt.Fprint(w, err)
return
}
http.Redirect(w, r, "/foo", 302)
})
http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
store, err := session.Start(context.Background(), w, r)
if err != nil {
fmt.Fprint(w, err)
return
}
foo, ok := store.Get("foo")
if ok {
fmt.Fprintf(w, "foo:%s", foo)
return
}
fmt.Fprint(w, "does not exist")
})
http.ListenAndServe(":8080", nil)
}
```
### Build and run
```bash
go run server.go
```
### Open in your web browser
foo:bar
## MIT License
Copyright (c) 2021 Lyric
[build-status-url]: https://travis-ci.org/go-session/redis
[build-status-image]: https://travis-ci.org/go-session/redis.svg?branch=master
[codecov-url]: https://codecov.io/gh/go-session/redis
[codecov-image]: https://codecov.io/gh/go-session/redis/branch/master/graph/badge.svg
[reportcard-url]: https://goreportcard.com/report/github.com/go-session/redis
[reportcard-image]: https://goreportcard.com/badge/github.com/go-session/redis
[godoc-url]: https://godoc.org/github.com/go-session/redis
[godoc-image]: https://godoc.org/github.com/go-session/redis?status.svg
[license-url]: http://opensource.org/licenses/MIT
[license-image]: https://img.shields.io/npm/l/express.svg