-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
106 lines (83 loc) · 1.44 KB
/
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
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"
cache "github.com/delanri/commonutil/cache/redis"
"log"
"sort"
"time"
)
func ch1() {
c, err := cache.New(&cache.Option{
Address: "localhost:6379",
PoolSize: 4,
})
if err != nil {
log.Fatal(err)
}
defer c.Close()
ps, _ := c.Subscribe("hello-world")
if err := ps.Receive(); err != nil {
log.Fatal(err)
}
ch := ps.Channel()
go func() {
for {
select {
case m := <-ch:
if m != nil {
log.Printf("ch 1 got message %s", m.Payload)
}
}
}
}()
for i := 0; i < 10; i++ {
if err := ps.Publish(fmt.Sprintf("hello world from %d", i)); err != nil {
log.Fatal(err)
}
}
}
func ch2() {
c, err := cache.New(&cache.Option{
Address: "localhost:6379",
PoolSize: 4,
})
if err != nil {
log.Fatal(err)
}
defer c.Close()
ps, _ := c.Subscribe("hello-world")
if err := ps.Receive(); err != nil {
log.Fatal(err)
}
ch := ps.Channel()
go func() {
for {
select {
case m := <-ch:
if m != nil {
log.Printf("ch 2 got message %s", m.Payload)
}
}
}
}()
for i := 0; i < 10; i++ {
if err := ps.Publish(fmt.Sprintf("hello world from %d", i)); err != nil {
log.Fatal(err)
}
}
}
func ok() {
go ch1()
go ch2()
time.Sleep(3 * time.Second)
}
func main() {
slices1 := []int64{3,5,1}
sort.Slice(slices1, func(l, r int) bool {
return slices1[l] < slices1[r]
})
slices2 := []int{3,5,1}
sort.Ints(slices2)
log.Println(slices1)
log.Println(slices2)
}