diff options
author | zeripath <art27@cantab.net> | 2020-09-27 22:09:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-28 00:09:46 +0300 |
commit | 7f8e3192cd941f008a3a2413ca0e9ff90c02fd88 (patch) | |
tree | a22a8feb40925b85fca67fff316ba45eef49155f /vendor/github.com/go-redis/redis/script.go | |
parent | f404bdde9bec5fb7badf3a5ca1c503a2a884f315 (diff) | |
download | gitea-7f8e3192cd941f008a3a2413ca0e9ff90c02fd88.tar.gz gitea-7f8e3192cd941f008a3a2413ca0e9ff90c02fd88.zip |
Allow common redis and leveldb connections (#12385)
* Allow common redis and leveldb connections
Prevents multiple reopening of redis and leveldb connections to the same
place by sharing connections.
Further allows for more configurable redis connection type using the
redisURI and a leveldbURI scheme.
Signed-off-by: Andrew Thornton <art27@cantab.net>
* add unit-test
Signed-off-by: Andrew Thornton <art27@cantab.net>
* as per @lunny
Signed-off-by: Andrew Thornton <art27@cantab.net>
* add test
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Update modules/cache/cache_redis.go
* Update modules/queue/queue_disk.go
* Update modules/cache/cache_redis.go
* Update modules/cache/cache_redis.go
* Update modules/queue/unique_queue_disk.go
* Update modules/queue/queue_disk.go
* Update modules/queue/unique_queue_disk.go
* Update modules/session/redis.go
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'vendor/github.com/go-redis/redis/script.go')
-rw-r--r-- | vendor/github.com/go-redis/redis/script.go | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/vendor/github.com/go-redis/redis/script.go b/vendor/github.com/go-redis/redis/script.go deleted file mode 100644 index 09f36d9320..0000000000 --- a/vendor/github.com/go-redis/redis/script.go +++ /dev/null @@ -1,62 +0,0 @@ -package redis - -import ( - "crypto/sha1" - "encoding/hex" - "io" - "strings" -) - -type scripter interface { - Eval(script string, keys []string, args ...interface{}) *Cmd - EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd - ScriptExists(hashes ...string) *BoolSliceCmd - ScriptLoad(script string) *StringCmd -} - -var _ scripter = (*Client)(nil) -var _ scripter = (*Ring)(nil) -var _ scripter = (*ClusterClient)(nil) - -type Script struct { - src, hash string -} - -func NewScript(src string) *Script { - h := sha1.New() - io.WriteString(h, src) - return &Script{ - src: src, - hash: hex.EncodeToString(h.Sum(nil)), - } -} - -func (s *Script) Hash() string { - return s.hash -} - -func (s *Script) Load(c scripter) *StringCmd { - return c.ScriptLoad(s.src) -} - -func (s *Script) Exists(c scripter) *BoolSliceCmd { - return c.ScriptExists(s.hash) -} - -func (s *Script) Eval(c scripter, keys []string, args ...interface{}) *Cmd { - return c.Eval(s.src, keys, args...) -} - -func (s *Script) EvalSha(c scripter, keys []string, args ...interface{}) *Cmd { - return c.EvalSha(s.hash, keys, args...) -} - -// Run optimistically uses EVALSHA to run the script. If script does not exist -// it is retried using EVAL. -func (s *Script) Run(c scripter, keys []string, args ...interface{}) *Cmd { - r := s.EvalSha(c, keys, args...) - if err := r.Err(); err != nil && strings.HasPrefix(err.Error(), "NOSCRIPT ") { - return s.Eval(c, keys, args...) - } - return r -} |