mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +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"
|
||||
)
|
||||
|
||||
var pool *simpleredis.ConnectionPool
|
||||
var (
|
||||
masterPool *simpleredis.ConnectionPool
|
||||
slavePool *simpleredis.ConnectionPool
|
||||
)
|
||||
|
||||
func ListRangeHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
key := mux.Vars(req)["key"]
|
||||
list := simpleredis.NewList(pool, key)
|
||||
list := simpleredis.NewList(slavePool, key)
|
||||
members := HandleError(list.GetAll()).([]string)
|
||||
membersJSON := HandleError(json.MarshalIndent(members, "", " ")).([]byte)
|
||||
rw.Write(membersJSON)
|
||||
@ -40,13 +43,13 @@ func ListRangeHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
func ListPushHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
key := mux.Vars(req)["key"]
|
||||
value := mux.Vars(req)["value"]
|
||||
list := simpleredis.NewList(pool, key)
|
||||
list := simpleredis.NewList(masterPool, key)
|
||||
HandleError(nil, list.Add(value))
|
||||
ListRangeHandler(rw, req)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@ -71,8 +74,10 @@ func HandleError(result interface{}, err error) (r interface{}) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
pool = simpleredis.NewConnectionPoolHost("redis-master:6379")
|
||||
defer pool.Close()
|
||||
masterPool = simpleredis.NewConnectionPoolHost("redis-master:6379")
|
||||
defer masterPool.Close()
|
||||
slavePool = simpleredis.NewConnectionPoolHost("redis-slave:6379")
|
||||
defer slavePool.Close()
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.Path("/lrange/{key}").Methods("GET").HandlerFunc(ListRangeHandler)
|
||||
|
Loading…
Reference in New Issue
Block a user