-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
69 lines (60 loc) · 1.18 KB
/
main.go
File metadata and controls
69 lines (60 loc) · 1.18 KB
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
package main
import (
"fmt"
"github.com/go-redis/redis"
"strconv"
"sync"
)
var Client *redis.Client
var wg sync.WaitGroup
func waiter(c chan int) {
wg.Wait()
fmt.Println("exit....")
c <- 1
}
func main() {
//Подключаемся к Redis
Client = redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
out := make(chan DevicesStruct)
GetAllDevicesFromDB(out)
waitme := make(chan int)
go waiter(waitme)
ex := 0
for ex == 0 {
select {
case x := <-out:
go func(x DevicesStruct) {
allMetrics := CreateMetric(x)
go func(m DevicesMetricStruct) {
checkMetrics(m)
wg.Done()
}(allMetrics)
}(x)
case <-waitme:
close(out)
close(waitme)
ex = 1
}
}
}
//Установить значения по ключу
func setValues(key int, value string) {
keyToStr := strconv.Itoa(key)
err := Client.Set(keyToStr, value, 0).Err()
if err != nil {
panic(err)
}
}
//Получить значения по ключу
func getValues(key int) string {
keyToStr := strconv.Itoa(key)
val, err := Client.Get(keyToStr).Result()
if err != nil {
//panic(err)
}
return val
}