forked from Azure-Samples/mslearn-aks-app-scaling-keda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (37 loc) · 947 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/go-redis/redis/v8"
"go.uber.org/zap"
)
var ctx = context.Background()
var logger *zap.Logger
func main() {
logger, _ = zap.NewDevelopment()
log.SetFlags(log.LstdFlags | log.Lshortfile)
host := os.Getenv("REDIS_HOST")
port := os.Getenv("REDIS_PORT")
listName := os.Getenv("REDIS_LIST")
password := os.Getenv("REDIS_KEY")
rdb := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", host, port),
Password: password, // no password set
DB: 0, // use default DB
})
for {
val3, err := rdb.LPop(ctx, listName).Result()
if err == redis.Nil {
logger.Sugar().Infof("%s list is empty, waiting 3 seconds...", listName)
time.Sleep(3 * time.Second)
} else if err != nil {
logger.Sugar().Panic(err)
} else {
logger.Sugar().Infof("processing list: %s and item: %s", listName, val3)
time.Sleep(3 * time.Second)
}
}
}