diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2021-10-24 13:10:20 -0400 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2021-10-24 13:10:20 -0400 |
| commit | e0d4a3e50921dc07e23ef9aa107bdc78b3adf176 (patch) | |
| tree | 3b7abcbc091cafd7591e91d0ad96e3b5760f3ba5 /rediscache/main.go | |
| parent | 268fcf7e6b671d4959a12111d5abf553bf0a201b (diff) | |
| download | go-website-0.0.15.tar.gz go-website-0.0.15.tar.xz | |
Use hash in redis. Key can be set in conf.v0.0.15
Diffstat (limited to 'rediscache/main.go')
| -rw-r--r-- | rediscache/main.go | 6 |
1 files changed, 3 insertions, 3 deletions
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) |
