Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #148 replaces redigo with redis-go #178

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,36 @@ func main() {
package main

import (
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
"context"
"github.com/gin-contrib/sessions"
redistore "github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis/v8"
)

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")
r := gin.Default()
redisClient := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
store, _ := redistore.NewStore(context.Background(), redisClient)
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")
}
```

Expand Down Expand Up @@ -251,6 +256,7 @@ func main() {
### MongoDB

#### mgo

```go
package main

Expand Down Expand Up @@ -291,7 +297,8 @@ func main() {
```

#### mongo-driver
```

```go
package main

import (
Expand Down Expand Up @@ -373,7 +380,8 @@ func main() {

### GoRM

[embedmd]:# (_example/gorm/main.go go)
[embedmd]: # "_example/gorm/main.go go"

```go
package main

Expand Down
9 changes: 7 additions & 2 deletions _example/redis/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package main

import (
"context"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/redis"
redistore "github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis/v8"
)

func main() {
r := gin.Default()
store, _ := redis.NewStore(10, "tcp", "localhost:6379", "", []byte("secret"))
redisClient := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
store, _ := redistore.NewStore(context.Background(), redisClient)
r.Use(sessions.Sessions("mysession", store))

r.GET("/incr", func(c *gin.Context) {
Expand Down
44 changes: 23 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,58 @@ module github.com/gin-contrib/sessions
go 1.18

require (
github.com/antonlindstrom/pgstore v0.0.0-20200229204646-b08ebf1105e0
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff
github.com/bos-hieu/mongostore v0.0.2
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
github.com/antonlindstrom/pgstore v0.0.0-20220421113606-e3a6e3fed12a
github.com/bos-hieu/mongostore v0.0.3
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d
github.com/bradleypeabody/gorilla-sessions-memcache v0.0.0-20181103040241-659414f458e1
github.com/gin-gonic/gin v1.8.1
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
github.com/gomodule/redigo v2.0.0+incompatible
github.com/go-redis/redis/v8 v8.11.5
github.com/gorilla/context v1.1.1
github.com/gorilla/sessions v1.2.1
github.com/kidstuff/mongostore v0.0.0-20181113001930-e650cd85ee4b
github.com/memcachier/mc v2.0.1+incompatible
github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b
github.com/rbcervilla/redisstore/v8 v8.1.0
github.com/wader/gormstore/v2 v2.0.0
go.mongodb.org/mongo-driver v1.9.1
gorm.io/driver/sqlite v1.3.4
gorm.io/gorm v1.23.5
gorm.io/gorm v1.23.6
)

require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-playground/validator/v10 v10.11.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/klauspost/compress v1.15.6 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lib/pq v1.10.3 // indirect
github.com/lib/pq v1.10.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
golang.org/x/text v0.3.6 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading