mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Merge pull request #6720 from invino4/slave
Make guestbook-go example use slaves
This commit is contained in:
commit
68c3f3a914
@ -27,11 +27,14 @@ import (
|
|||||||
"github.com/xyproto/simpleredis"
|
"github.com/xyproto/simpleredis"
|
||||||
)
|
)
|
||||||
|
|
||||||
var pool *simpleredis.ConnectionPool
|
var (
|
||||||
|
masterPool *simpleredis.ConnectionPool
|
||||||
|
slavePool *simpleredis.ConnectionPool
|
||||||
|
)
|
||||||
|
|
||||||
func ListRangeHandler(rw http.ResponseWriter, req *http.Request) {
|
func ListRangeHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
key := mux.Vars(req)["key"]
|
key := mux.Vars(req)["key"]
|
||||||
list := simpleredis.NewList(pool, key)
|
list := simpleredis.NewList(slavePool, key)
|
||||||
members := HandleError(list.GetAll()).([]string)
|
members := HandleError(list.GetAll()).([]string)
|
||||||
membersJSON := HandleError(json.MarshalIndent(members, "", " ")).([]byte)
|
membersJSON := HandleError(json.MarshalIndent(members, "", " ")).([]byte)
|
||||||
rw.Write(membersJSON)
|
rw.Write(membersJSON)
|
||||||
@ -40,13 +43,13 @@ func ListRangeHandler(rw http.ResponseWriter, req *http.Request) {
|
|||||||
func ListPushHandler(rw http.ResponseWriter, req *http.Request) {
|
func ListPushHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
key := mux.Vars(req)["key"]
|
key := mux.Vars(req)["key"]
|
||||||
value := mux.Vars(req)["value"]
|
value := mux.Vars(req)["value"]
|
||||||
list := simpleredis.NewList(pool, key)
|
list := simpleredis.NewList(masterPool, key)
|
||||||
HandleError(nil, list.Add(value))
|
HandleError(nil, list.Add(value))
|
||||||
ListRangeHandler(rw, req)
|
ListRangeHandler(rw, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func InfoHandler(rw http.ResponseWriter, req *http.Request) {
|
func InfoHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
info := HandleError(pool.Get(0).Do("INFO")).([]byte)
|
info := HandleError(masterPool.Get(0).Do("INFO")).([]byte)
|
||||||
rw.Write(info)
|
rw.Write(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,8 +74,10 @@ func HandleError(result interface{}, err error) (r interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
pool = simpleredis.NewConnectionPoolHost("redis-master:6379")
|
masterPool = simpleredis.NewConnectionPoolHost("redis-master:6379")
|
||||||
defer pool.Close()
|
defer masterPool.Close()
|
||||||
|
slavePool = simpleredis.NewConnectionPoolHost("redis-slave:6379")
|
||||||
|
defer slavePool.Close()
|
||||||
|
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
r.Path("/lrange/{key}").Methods("GET").HandlerFunc(ListRangeHandler)
|
r.Path("/lrange/{key}").Methods("GET").HandlerFunc(ListRangeHandler)
|
||||||
|
Loading…
Reference in New Issue
Block a user