aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/server/app.go1
-rw-r--r--cmd/server/handlers.go2
-rw-r--r--cmd/server/main.go8
-rw-r--r--rediscache/main.go6
4 files changed, 11 insertions, 6 deletions
diff --git a/cmd/server/app.go b/cmd/server/app.go
index 290b44a..c4992ae 100644
--- a/cmd/server/app.go
+++ b/cmd/server/app.go
@@ -13,6 +13,7 @@ var FeedPrefixDefault = ".feeds"
type App struct {
redisPool *redis.Pool
+ RedisKey string
ReIndexPath string
StaticDirectory string
diff --git a/cmd/server/handlers.go b/cmd/server/handlers.go
index 869e5ba..61bb623 100644
--- a/cmd/server/handlers.go
+++ b/cmd/server/handlers.go
@@ -19,7 +19,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if a.redisPool != nil {
rtr.PathPrefix("/").Handler(rediscache.Handle(
- a.redisPool, http.HandlerFunc(a.PageHandler)))
+ a.redisPool, a.RedisKey, http.HandlerFunc(a.PageHandler)))
} else {
rtr.PathPrefix("/").Handler(http.HandlerFunc(a.PageHandler))
}
diff --git a/cmd/server/main.go b/cmd/server/main.go
index d76f938..21f7031 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -34,8 +34,8 @@ func main() { //nolint:funlen
indexPath := fl.String("i", defaultIndexPath,
"Path in which, when called will rebuild the index and clear the cache")
- redisAddr := fl.String("r", "127.0.0.1:6379",
- "Redis server set to \"\" to disable")
+ redisAddr := fl.String("r", "127.0.0.1:6379", "Redis server set to \"\" to disable")
+ redisKey := fl.String("rk", "go-website", "Redis key to use for storing cached pages")
pageTimeout := fl.Int("timeout", 15, "Seconds until page timeout for read and write")
@@ -63,6 +63,10 @@ func main() { //nolint:funlen
app.ReIndexPath = *indexPath
}
+ if app.RedisKey == "" {
+ app.RedisKey = *redisKey
+ }
+
if *redisAddr != "" {
app.redisPool = &redis.Pool{
MaxIdle: 80, //nolint:gomnd
diff --git a/rediscache/main.go b/rediscache/main.go
index e7564c8..7ae3d4d 100644
--- a/rediscache/main.go
+++ b/rediscache/main.go
@@ -57,13 +57,13 @@ func (rw *redisHTTPResponseWriter) WriteData() {
// Simple function that will cache the response for given handler in redis
// and instead of responding with the result from the handler it will
// simply dump the contents of the redis key if it exists.
-func Handle(pool *redis.Pool, next http.Handler) http.Handler {
+func Handle(pool *redis.Pool, key string, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
client := pool.Get()
defer client.Close()
content:
- data, err := client.Do("GET", r.URL.Path)
+ data, err := client.Do("HGET", key, r.URL.Path)
if err != nil {
// Assume something bad has happened with redis, we're
// just going to log this and then pass through the
@@ -83,7 +83,7 @@ func Handle(pool *redis.Pool, next http.Handler) http.Handler {
return
}
- _, err = client.Do("SET", r.URL.Path, b)
+ _, err = client.Do("HSET", key, r.URL.Path, b)
if err != nil {
Logger.Println("ERROR: during set: ", err)