From 5a74fbcf4253888aab3fd56877581943684e3918 Mon Sep 17 00:00:00 2001 From: Julien Moutinho Date: Wed, 8 Dec 2021 00:33:54 +0100 Subject: [PATCH] gitsrht-update-hook: update go-redis to support Unix sockets --- gitsrht-update-hook/options.go | 11 ++++++----- gitsrht-update-hook/post-update.go | 5 +++-- gitsrht-update-hook/update.go | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/gitsrht-update-hook/options.go b/gitsrht-update-hook/options.go index 8efbb0a..adec6a5 100644 --- a/gitsrht-update-hook/options.go +++ b/gitsrht-update-hook/options.go @@ -1,13 +1,14 @@ package main import ( + "context" "fmt" "os" "strconv" "strings" "time" - goredis "github.com/go-redis/redis" + goredis "github.com/go-redis/redis/v8" ) var options map[string]string @@ -35,10 +36,10 @@ func loadOptions() { var n int if nopts, ok := os.LookupEnv("GIT_PUSH_OPTION_COUNT"); ok { n, _ = strconv.Atoi(nopts) - redis.Set(fmt.Sprintf("git.sr.ht.options.%s", uuid), + redis.Set(context.Background(), fmt.Sprintf("git.sr.ht.options.%s", uuid), nopts, 10*time.Minute) } else { - nopts, err := redis.Get(fmt.Sprintf( + nopts, err := redis.Get(context.Background(), fmt.Sprintf( "git.sr.ht.options.%s", uuid)).Result() if err != nil { return @@ -51,12 +52,12 @@ func loadOptions() { opt, ok := os.LookupEnv(fmt.Sprintf("GIT_PUSH_OPTION_%d", i)) optkey := fmt.Sprintf("git.sr.ht.options.%s.%d", uuid, i) if !ok { - opt, err = redis.Get(optkey).Result() + opt, err = redis.Get(context.Background(), optkey).Result() if err != nil { return } } else { - redis.Set(optkey, opt, 10*time.Minute) + redis.Set(context.Background(), optkey, opt, 10*time.Minute) } parts := strings.SplitN(opt, "=", 2) if len(parts) == 1 { diff --git a/gitsrht-update-hook/post-update.go b/gitsrht-update-hook/post-update.go index 757d4c2..f3c366a 100644 --- a/gitsrht-update-hook/post-update.go +++ b/gitsrht-update-hook/post-update.go @@ -1,6 +1,7 @@ package main import ( + ctx "context" "database/sql" "encoding/json" "fmt" @@ -15,7 +16,7 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/plumbing/storer" - goredis "github.com/go-redis/redis" + goredis "github.com/go-redis/redis/v8" _ "github.com/lib/pq" ) @@ -220,7 +221,7 @@ func postUpdate() { var oldref, newref string var oldobj, newobj object.Object updateKey := fmt.Sprintf("update.%s.%s", pushUuid, refname) - update, err := redis.Get(updateKey).Result() + update, err := redis.Get(ctx.Background(), updateKey).Result() if update == "" || err != nil { logger.Println("redis.Get: missing key") continue diff --git a/gitsrht-update-hook/update.go b/gitsrht-update-hook/update.go index 72c661a..bba1ec8 100644 --- a/gitsrht-update-hook/update.go +++ b/gitsrht-update-hook/update.go @@ -1,11 +1,12 @@ package main import ( + "context" "fmt" "os" "time" - goredis "github.com/go-redis/redis" + goredis "github.com/go-redis/redis/v8" ) // XXX: This is run once for every single ref that's pushed. If someone pushes @@ -31,6 +32,6 @@ func update() { logger.Fatalf("Failed to parse redis host: %v", err) } redis := goredis.NewClient(ropts) - redis.Set(fmt.Sprintf("update.%s.%s", pushUuid, refname), + redis.Set(context.Background(), fmt.Sprintf("update.%s.%s", pushUuid, refname), fmt.Sprintf("%s:%s", oldref, newref), 10*time.Minute) } -- 2.38.4