Implement redis caching

parent 6bd61914
package main
import (
"encoding/json"
"git.kuschku.de/justjanne/bahn-api"
"github.com/go-redis/cache"
"github.com/go-redis/redis"
"time"
)
type RedisCache struct {
backend *cache.Codec
expirationTime time.Duration
}
func (m RedisCache) Set(key string, value interface{}) error {
return m.backend.Set(&cache.Item{
Key: key,
Object: value,
Expiration: m.expirationTime,
})
}
func (m RedisCache) Get(key string, value interface{}) error {
return m.backend.Get(key, &value)
}
func NewRedisCache(expirationTime time.Duration) bahn.CacheBackend {
return RedisCache{
backend: &cache.Codec{
Redis: redis.NewClient(&redis.Options{
}),
Marshal: json.Marshal,
Unmarshal: json.Unmarshal,
},
}
}
......@@ -4,5 +4,7 @@ go 1.12
require (
git.kuschku.de/justjanne/bahn-api v0.0.0-20190504114009-71c830fe0812
github.com/go-redis/cache v6.3.5+incompatible
github.com/go-redis/redis v6.15.2+incompatible
github.com/patrickmn/go-cache v2.1.0+incompatible
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment