From cc6ace188dae8eba4177ced9d8ddd205f6e3d0f3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 17:12:56 +0800 Subject: [PATCH] chore(deps): bump github.com/beego/beego/v2 from 2.2.1 to 2.3.4 in /src (#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](https://github.com/beego/beego/compare/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] * add SessionReleaseIfPresent for session Store implenmentation Signed-off-by: yminer --------- Signed-off-by: dependabot[bot] Signed-off-by: yminer Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: yminer --- src/core/session/session.go | 33 ++++++++++++++++++++++++++------- src/go.mod | 2 +- src/go.sum | 4 ++-- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/core/session/session.go b/src/core/session/session.go index 77b57f82607..448ed1a971b 100644 --- a/src/core/session/session.go +++ b/src/core/session/session.go @@ -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 diff --git a/src/go.mod b/src/go.mod index 042461b80bf..d690ceb3ac7 100644 --- a/src/go.mod +++ b/src/go.mod @@ -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 diff --git a/src/go.sum b/src/go.sum index 0b008375705..2466f4039b4 100644 --- a/src/go.sum +++ b/src/go.sum @@ -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=