Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
2ecb95b5
Commit
2ecb95b5
authored
Apr 10, 2015
by
Jason Hunter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make guestbook-go example actually use the redis-slave service that is set up for its reads.
parent
fff6cebb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
main.go
examples/guestbook-go/_src/main.go
+11
-6
No files found.
examples/guestbook-go/_src/main.go
View file @
2ecb95b5
...
@@ -27,11 +27,14 @@ import (
...
@@ -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
(
p
ool
,
key
)
list
:=
simpleredis
.
NewList
(
slaveP
ool
,
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) {
...
@@ -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
(
p
ool
,
key
)
list
:=
simpleredis
.
NewList
(
masterP
ool
,
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
(
p
ool
.
Get
(
0
)
.
Do
(
"INFO"
))
.
([]
byte
)
info
:=
HandleError
(
masterP
ool
.
Get
(
0
)
.
Do
(
"INFO"
))
.
([]
byte
)
rw
.
Write
(
info
)
rw
.
Write
(
info
)
}
}
...
@@ -71,8 +74,10 @@ func HandleError(result interface{}, err error) (r interface{}) {
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment