Skip to content

Commit

Permalink
chore(deps): bump github.com/beego/beego/v2 from 2.2.1 to 2.3.4 in /s…
Browse files Browse the repository at this point in the history
…rc (#21321)

* chore(deps): bump github.com/beego/beego/v2 from 2.2.1 to 2.3.4 in /src

Bumps [github.com/beego/beego/v2](https://github.com/beego/beego) from 2.2.1 to 2.3.4.
- [Release notes](https://github.com/beego/beego/releases)
- [Changelog](https://github.com/beego/beego/blob/master/CHANGELOG.md)
- [Commits](beego/beego@v2.2.1...v2.3.4)

---
updated-dependencies:
- dependency-name: github.com/beego/beego/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* add SessionReleaseIfPresent for session Store implenmentation

Signed-off-by: yminer <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: yminer <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: yminer <[email protected]>
  • Loading branch information
dependabot[bot] and yminer authored Jan 14, 2025
1 parent 7c502a8 commit cc6ace1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
33 changes: 26 additions & 7 deletions src/core/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,44 @@ func (rs *Store) SessionID(_ context.Context) string {
return rs.sid
}

// SessionRelease save session values to redis
func (rs *Store) SessionRelease(ctx context.Context, _ http.ResponseWriter) {
b, err := session.EncodeGob(rs.values)
func (rs *Store) releaseSession(ctx context.Context, _ http.ResponseWriter, requirePresent bool) {
rs.lock.RLock()
values := rs.values
rs.lock.RUnlock()
b, err := session.EncodeGob(values)
if err != nil {
return
}

if ctx == nil {
ctx = context.TODO()
}
maxlifetime := time.Duration(systemSessionTimeout(ctx, rs.maxlifetime))
if rdb, ok := rs.c.(*redis.Cache); ok {
cmd := rdb.Client.Set(ctx, rs.sid, string(b), maxlifetime)
if cmd.Err() != nil {
log.Debugf("release session error: %v", err)
if requirePresent {
cmd := rdb.Client.SetXX(ctx, rs.sid, string(b), maxlifetime)
if cmd.Err() != nil {
log.Debugf("release session error: %v", err)
}
} else {
cmd := rdb.Client.Set(ctx, rs.sid, string(b), maxlifetime)
if cmd.Err() != nil {
log.Debugf("release session error: %v", err)
}
}
}
}

// SessionRelease save session values to redis
func (rs *Store) SessionRelease(ctx context.Context, w http.ResponseWriter) {
rs.releaseSession(ctx, w, false)
}

// added by beego version v2.3.4, commit https://github.com/beego/beego/commit/06d869664a9c55aea6c2bb6ac3866f8a39b1100c#diff-bc81cfdba9f5250f9bf95ccaae2e4e34b37af87e2091dda11ef49dc58bd91c2c
// SessionReleaseIfPresent save session values to redis when key is present
func (rs *Store) SessionReleaseIfPresent(ctx context.Context, w http.ResponseWriter) {
rs.releaseSession(ctx, w, true)
}

// Provider redis session provider
type Provider struct {
maxlifetime int64
Expand Down
2 changes: 1 addition & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/aliyun/alibaba-cloud-sdk-go v1.63.47
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
github.com/aws/aws-sdk-go v1.55.5
github.com/beego/beego/v2 v2.2.1
github.com/beego/beego/v2 v2.3.4
github.com/beego/i18n v0.0.0-20140604031826-e87155e8f0c0
github.com/bmatcuk/doublestar v1.3.4
github.com/casbin/casbin v1.9.1
Expand Down
4 changes: 2 additions & 2 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:W
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/beego/beego/v2 v2.2.1 h1:5RatpEOKnw6sm76hj6lQvEFi4Tco+E21VQomnVB7NsA=
github.com/beego/beego/v2 v2.2.1/go.mod h1:X4hHhM2AXn0hN2tbyz5X/PD7v5JUdE4IihZApiljpNA=
github.com/beego/beego/v2 v2.3.4 h1:HurQEOGIEhLlPFCTR6ZDuQkybrUl2Ag2i6CdVD2rGiI=
github.com/beego/beego/v2 v2.3.4/go.mod h1:5cqHsOHJIxkq44tBpRvtDe59GuVRVv/9/tyVDxd5ce4=
github.com/beego/i18n v0.0.0-20140604031826-e87155e8f0c0 h1:fQaDnUQvBXHHQdGBu9hz8nPznB4BeiPQokvmQVjmNEw=
github.com/beego/i18n v0.0.0-20140604031826-e87155e8f0c0/go.mod h1:KLeFCpAMq2+50NkXC8iiJxLLiiTfTqrGtKEVm+2fk7s=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down

0 comments on commit cc6ace1

Please sign in to comment.