forked from swoole/swoole-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.go
37 lines (30 loc) · 743 Bytes
/
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
package main
import (
"fmt"
"log"
"net/http"
"github.com/hoisie/redis"
"runtime"
)
var (
client *redis.Client
)
func main() {
client = &redis.Client{
Addr: "127.0.0.1:6379",
Db: 0,
MaxPoolSize: 10000,
}
// 限制为CPU的数量减一
runtime.GOMAXPROCS( runtime.NumCPU() - 1 )
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
result, err := client.Get("hello")
if err != nil {
fmt.Fprint(w, err.Error())
println(err.Error())
} else {
fmt.Fprint(w, "<h1>Hello world!. result="+ string(result)+"</h1>")
}
})
log.Fatal(http.ListenAndServe(":8080", nil))
}