-
Notifications
You must be signed in to change notification settings - Fork 1
/
system_redis.go
106 lines (100 loc) · 3.32 KB
/
system_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"strconv"
"strings"
s "github.com/ValidatorCenter/prs3r/strc"
"github.com/go-redis/redis"
)
// Получение данных Системной таблицы из SQL
func srchSysSql(db *redis.Client) s.StatusDB {
p := s.StatusDB{}
strc := "latest_block_save,latest_block_cmc,latest_block_vld,latest_block_rwd"
arr := strings.Split(strc, ",")
len_arr := len(arr)
if len_arr == 0 {
log("ERR", fmt.Sprint("[mem_sys.go] srchSysSql(len(arr)) - ", "=0!"), "")
return s.StatusDB{}
}
for i := 0; i < len_arr; i++ {
switch arr[i] {
case "latest_block_save":
_lbRes, err := db.Get(arr[i]).Result()
if err == redis.Nil {
p.LatestBlockSave = 0
log("WRN", fmt.Sprint("[mem_sys.go] srchSysSql(Get...", arr[i], ") - ", "=0!"), "")
} else if err != nil {
log("ERR", fmt.Sprint("[mem_sys.go] srchSysSql(Get...", arr[i], ") - ", err), "")
return s.StatusDB{}
}
if _lbRes != "" {
p.LatestBlockSave, err = strconv.Atoi(_lbRes)
if err != nil {
log("ERR", fmt.Sprint("[mem_sys.go] strconv.Atoi(", arr[i], ") - ", err), "")
return s.StatusDB{}
}
} else {
log("WRN", fmt.Sprint("[mem_sys.go] Нет в MEM - ", arr[i], " => будет значит 0 "), "")
p.LatestBlockSave = 0
}
case "latest_block_cmc":
_lbRes, err := db.Get(arr[i]).Result()
if err == redis.Nil {
p.LatestBlockCMC = 0
log("WRN", fmt.Sprint("[mem_sys.go] srchSysSql(Get...", arr[i], ") - ", "=0!"), "")
} else if err != nil {
log("ERR", fmt.Sprint("[mem_sys.go] srchSysSql(Get...", arr[i], ") - ", err), "")
return s.StatusDB{}
}
if _lbRes != "" {
p.LatestBlockCMC, err = strconv.Atoi(_lbRes)
if err != nil {
log("ERR", fmt.Sprint("[mem_sys.go] strconv.Atoi(", arr[i], ") - ", err), "")
return s.StatusDB{}
}
} else {
log("WRN", fmt.Sprint("[mem_sys.go] Нет в MEM - ", arr[i], " => будет значит 0 "), "")
p.LatestBlockCMC = 0
}
case "latest_block_vld":
_lbRes, err := db.Get(arr[i]).Result()
if err == redis.Nil {
p.LatestBlockVld = 0
log("WRN", fmt.Sprint("[mem_sys.go] srchSysSql(Get...", arr[i], ") - ", "=0!"), "")
} else if err != nil {
log("ERR", fmt.Sprint("[mem_sys.go] srchSysSql(Get...", arr[i], ") - ", err), "")
return s.StatusDB{}
}
if _lbRes != "" {
p.LatestBlockVld, err = strconv.Atoi(_lbRes)
if err != nil {
log("ERR", fmt.Sprint("[mem_sys.go] strconv.Atoi(", arr[i], ") - ", err), "")
return s.StatusDB{}
}
} else {
log("WRN", fmt.Sprint("[mem_sys.go] Нет в MEM - ", arr[i], " => будет значит 0 "), "")
p.LatestBlockVld = 0
}
case "latest_block_rwd":
_lbRes, err := db.Get(arr[i]).Result()
if err == redis.Nil {
p.LatestBlockRwd = 0
log("WRN", fmt.Sprint("[mem_sys.go] srchSysSql(Get...", arr[i], ") - ", "=0!"), "")
} else if err != nil {
log("ERR", fmt.Sprint("[mem_sys.go] srchSysSql(Get...", arr[i], ") - ", err), "")
return s.StatusDB{}
}
if _lbRes != "" {
p.LatestBlockRwd, err = strconv.Atoi(_lbRes)
if err != nil {
log("ERR", fmt.Sprint("[mem_sys.go] strconv.Atoi(", arr[i], ") - ", err), "")
return s.StatusDB{}
}
} else {
log("WRN", fmt.Sprint("[mem_sys.go] Нет в MEM - ", arr[i], " => будет значит 0 "), "")
p.LatestBlockRwd = 0
}
}
}
return p
}