From e0d4a3e50921dc07e23ef9aa107bdc78b3adf176 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Sun, 24 Oct 2021 13:10:20 -0400 Subject: Use hash in redis. Key can be set in conf. --- rediscache/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'rediscache/main.go') 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) -- cgit v1.2.3