-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis.go
62 lines (52 loc) · 1.21 KB
/
redis.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"log"
"github.com/go-redis/redis"
)
var rdb *redis.Client
func InitialiseRedis() {
rdb = redis.NewClient(&redis.Options{
Addr: redisHost,
Password: redisPassword,
DB: redisDb,
})
_, err := rdb.Ping().Result()
if err != nil {
panic("Redis :: Failed to connect to Redis:" + err.Error())
}
}
func RedisConnected() bool {
_, err := rdb.Ping().Result()
if err != nil {
return false
}
return true
}
func GetRedisClient() *redis.Client {
return rdb
}
func SetInRedis(key string, value string) {
rdb := GetRedisClient()
err := rdb.Set(key, value, redisKeyLifetime).Err()
if err != nil {
log.Println("Redis :: Unable to set in Redis with key: ", key, "due to: ", err.Error())
}
}
func GetFromRedis(key string) string {
rdb := GetRedisClient()
val, err := rdb.Get(key).Result()
if err != nil {
if err == redis.Nil {
return ""
} else {
log.Println("Redis :: Unable to get from Redis with key: ", key, "due to: ", err.Error())
}
}
return val
}
func FormRedisKey(cargoToml string, mainRs string) string {
project := cargoToml + mainRs
base64dProject := base64Encoder(project)
hashedEncodedProject := GetMd5StringOfInput(base64dProject)
return hashedEncodedProject
}