add example for memory storage og gsession

This commit is contained in:
John
2019-11-05 17:33:06 +08:00
parent 21abe62633
commit 6c54e73dbd
9 changed files with 217 additions and 10 deletions

View File

@ -0,0 +1,30 @@
package main
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/gsession"
"github.com/gogf/gf/os/gtime"
"time"
)
func main() {
s := g.Server()
s.SetConfigWithMap(g.Map{
"SessionMaxAge": time.Minute,
"SessionStorage": gsession.NewStorageMemory(),
})
s.BindHandler("/set", func(r *ghttp.Request) {
r.Session.Set("time", gtime.Second())
r.Response.Write("ok")
})
s.BindHandler("/get", func(r *ghttp.Request) {
r.Response.Write(r.Session.Map())
})
s.BindHandler("/del", func(r *ghttp.Request) {
r.Session.Clear()
r.Response.Write("ok")
})
s.SetPort(8199)
s.Run()
}

View File

@ -11,7 +11,7 @@ import (
func main() {
s := g.Server()
s.SetConfigWithMap(g.Map{
"SessionMaxAge": 60 * time.Minute,
"SessionMaxAge": time.Minute,
"SessionStorage": gsession.NewStorageRedisHashTable(g.Redis()),
})
s.BindHandler("/set", func(r *ghttp.Request) {