updates to main.go

This commit is contained in:
Emily Moss 2021-07-09 15:01:25 -07:00
parent 93fb5c3169
commit 414fa0165e
1 changed files with 4 additions and 4 deletions

View File

@ -29,12 +29,12 @@ import (
var ( var (
masterPool *simpleredis.ConnectionPool masterPool *simpleredis.ConnectionPool
slavePool *simpleredis.ConnectionPool replicaPool *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(slavePool, key) list := simpleredis.NewList(replicaPool, 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)
@ -76,8 +76,8 @@ func HandleError(result interface{}, err error) (r interface{}) {
func main() { func main() {
masterPool = simpleredis.NewConnectionPoolHost("redis-master:6379") masterPool = simpleredis.NewConnectionPoolHost("redis-master:6379")
defer masterPool.Close() defer masterPool.Close()
slavePool = simpleredis.NewConnectionPoolHost("redis-slave:6379") replicaPool = simpleredis.NewConnectionPoolHost("redis-slave:6379")
defer slavePool.Close() defer replicaPool.Close()
r := mux.NewRouter() r := mux.NewRouter()
r.Path("/lrange/{key}").Methods("GET").HandlerFunc(ListRangeHandler) r.Path("/lrange/{key}").Methods("GET").HandlerFunc(ListRangeHandler)