From 1ee674068864a416acd673ee32248b57fc31fb07 Mon Sep 17 00:00:00 2001 From: Matthias Hannig Date: Thu, 24 Jan 2019 19:01:05 +0100 Subject: [PATCH 1/2] improved caching tests --- bird/redis_cache_test.go | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bird/redis_cache_test.go b/bird/redis_cache_test.go index e54c546..a8b6103 100644 --- a/bird/redis_cache_test.go +++ b/bird/redis_cache_test.go @@ -56,3 +56,45 @@ func Test_RedisCacheAccessKeyMissing(t *testing.T) { t.Log("Cache error:", err) t.Log(parsed) } + +func Test_RedisCacheRoutes(t *testing.T) { + f, err := openFile("routes_bird1_ipv4.sample") + if err != nil { + t.Error(err) + } + defer f.Close() + + parsed := parseRoutes(f) + _, ok := parsed["routes"].([]Parsed) + if !ok { + t.Fatal("Error getting routes") + } + + cache, err := NewRedisCache(CacheConfig{ + RedisServer: "localhost:6379", + }) + + if err != nil { + t.Log("Redis server not available:", err) + t.Log("Skipping redis tests.") + return + } + + err = cache.Set("routes_protocol_test", parsed) + if err != nil { + t.Error(err) + } + + parsed, err = cache.Get("routes_protocol_test") + if err != nil { + t.Error(err) + return + } + + routes, ok := parsed["routes"].([]interface{}) + if !ok { + t.Error("Error getting routes") + } + + t.Log("Retrieved routes:", len(routes)) +} From 837c97da13db14f77d29038ea831d722f49e4471 Mon Sep 17 00:00:00 2001 From: Matthias Hannig Date: Thu, 24 Jan 2019 19:01:41 +0100 Subject: [PATCH 2/2] prefix cache key for use with birdc and birdc6 --- bird/bird.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bird/bird.go b/bird/bird.go index f93c182..32424d5 100644 --- a/bird/bird.go +++ b/bird/bird.go @@ -52,6 +52,7 @@ func fromCacheMemory(key string) (Parsed, bool) { } func fromCacheRedis(key string) (Parsed, bool) { + key = "B" + IPVersion + "_" + key val, err := CacheRedis.Get(key) if err != nil { return NilParse, false @@ -81,6 +82,7 @@ func toCacheMemory(key string, val Parsed) { } func toCacheRedis(key string, val Parsed) { + key = "B" + IPVersion + "_" + key val["ttl"] = time.Now().Add(5 * time.Minute) err := CacheRedis.Set(key, val) if err != nil {