mirror of
https://github.com/go-gitea/gitea.git
synced 2026-12-04 15:54:57 +00:00
Update dependencies. chartjs-plugin-zoom 3 drops Hammer.js, which shrinks the contributors chart bundle by about 14 KB. Adapt to the updates: use rolldown's `bundlerTimings` instead of the deprecated `pluginTimings`, drop an asciinema-player style override that 3.19 makes redundant, and retry the Redis session backend's startup ping like the cache and queue setup do, because go-redis 9.24 gives up on a refused connection sooner. Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: silverwind <me@silverwind.io>
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
// Copyright 2013 Beego Authors
|
|
// Copyright 2014 The Macaron Authors
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package session
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"gitea.dev/modules/graceful"
|
|
"gitea.dev/modules/nosql"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
type redisBackend struct {
|
|
client redis.UniversalClient
|
|
prefix string
|
|
maxLifetime time.Duration
|
|
}
|
|
|
|
func newRedisBackend(config string, maxLifetime int64) (*redisBackend, error) {
|
|
uri := nosql.ToRedisURI(config)
|
|
b := &redisBackend{
|
|
client: nosql.GetManager().GetRedisClient(uri.String()),
|
|
prefix: uri.Query().Get("prefix"),
|
|
maxLifetime: time.Duration(maxLifetime) * time.Second,
|
|
}
|
|
var err error
|
|
for range 10 {
|
|
if err = b.client.Ping(graceful.GetManager().ShutdownContext()).Err(); err == nil {
|
|
break
|
|
}
|
|
time.Sleep(time.Second)
|
|
}
|
|
return b, err
|
|
}
|
|
|
|
func (b *redisBackend) load(sid string) ([]byte, error) {
|
|
ctx := graceful.GetManager().HammerContext()
|
|
var get *redis.StringCmd
|
|
_, err := b.client.Pipelined(ctx, func(pipe redis.Pipeliner) error {
|
|
get = pipe.Get(ctx, b.prefix+sid)
|
|
pipe.Expire(ctx, b.prefix+sid, b.maxLifetime)
|
|
return nil
|
|
})
|
|
if errors.Is(err, redis.Nil) {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return get.Bytes()
|
|
}
|
|
|
|
func (b *redisBackend) save(sid string, data []byte, create bool) error {
|
|
ctx := graceful.GetManager().HammerContext()
|
|
if create {
|
|
return b.client.Set(ctx, b.prefix+sid, data, b.maxLifetime).Err()
|
|
}
|
|
return b.client.SetXX(ctx, b.prefix+sid, data, b.maxLifetime).Err()
|
|
}
|
|
|
|
func (b *redisBackend) destroy(sid string) error {
|
|
return b.client.Del(graceful.GetManager().HammerContext(), b.prefix+sid).Err()
|
|
}
|
|
|
|
func (*redisBackend) gc() {}
|