質問編集履歴
1
例を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -37,3 +37,93 @@
|
|
37
37
|
|
38
38
|
|
39
39
|
このような場合どのような書き方をするのが適切なのでしょうか。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
<追記>
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
例えば以下のようなケースではどうでしょうか?
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```go
|
52
|
+
|
53
|
+
package main
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
import (
|
58
|
+
|
59
|
+
"fmt"
|
60
|
+
|
61
|
+
"time"
|
62
|
+
|
63
|
+
"strconv"
|
64
|
+
|
65
|
+
"encoding/json"
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
"github.com/go-redis/redis"
|
70
|
+
|
71
|
+
)
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
func main() {
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
client := redis.NewClient(&redis.Options{
|
80
|
+
|
81
|
+
Addr: "127.0.0.1:6379",
|
82
|
+
|
83
|
+
Password: "password",
|
84
|
+
|
85
|
+
DB: 0,
|
86
|
+
|
87
|
+
})
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
now := time.Now()
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
data := map[string]interface{} {
|
96
|
+
|
97
|
+
"key": "foo",
|
98
|
+
|
99
|
+
"value": "bar",
|
100
|
+
|
101
|
+
"time": strconv.FormatInt(now.Unix(), 10),
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
bytes, err1 := json.Marshal(data)
|
108
|
+
|
109
|
+
if err1 != nil {
|
110
|
+
|
111
|
+
panic(err1)
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
err2 := client.RPush("VALUES", string(bytes)).Err()
|
118
|
+
|
119
|
+
if err2 != nil {
|
120
|
+
|
121
|
+
panic(err2)
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
```
|