From d59df04738eda1598f6b2203a7bad13676a61b1b Mon Sep 17 00:00:00 2001 From: Mike Flynn Date: Wed, 24 Feb 2016 13:40:58 -0800 Subject: [PATCH 1/2] Added method and associated code to allow for the test and resetting of the redis (or other data store) connections for long running processes. --- redis.go | 13 +++++++++++++ shield.go | 4 ++++ types.go | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/redis.go b/redis.go index d81fdef..9a0c4fa 100644 --- a/redis.go +++ b/redis.go @@ -50,6 +50,19 @@ func (rs *RedisStore) conn() (conn redis.Conn, err error) { return rs.redis, nil } +func (rs *RedisStore) TestConnection() { + if c, err := rs.conn(); err == nil { + if _, err := c.Do("PING"); err == nil { + return + } + } + + log.Println("Resetting redis connection...") + + rs.redis = nil + rs.conn() +} + func (rs *RedisStore) Classes() (a []string, err error) { c, err := rs.conn() if err != nil { diff --git a/shield.go b/shield.go index 6fcc5aa..397fdf8 100644 --- a/shield.go +++ b/shield.go @@ -158,3 +158,7 @@ func (s *shield) Classify(text string) (class string, err error) { func (sh *shield) Reset() error { return sh.store.Reset() } + +func (sh *shield) TestConnection() { + sh.store.TestConnection() +} diff --git a/types.go b/types.go index 9f337f8..6de1a6d 100644 --- a/types.go +++ b/types.go @@ -27,6 +27,9 @@ type Shield interface { // Reset clears the storage Reset() error + + // Checks and reestablishes connection to the data store + TestConnection() } type Store interface { @@ -36,4 +39,5 @@ type Store interface { IncrementClassWordCounts(m map[string]map[string]int64) error TotalClassWordCounts() (map[string]int64, error) Reset() error + TestConnection() } From ec5ffbd348a893b3a926a8700cd7e957942eb9b7 Mon Sep 17 00:00:00 2001 From: Mike Flynn Date: Tue, 3 Mar 2020 19:41:43 -0800 Subject: [PATCH 2/2] Updated redis library. --- redis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis.go b/redis.go index 9a0c4fa..e366a42 100644 --- a/redis.go +++ b/redis.go @@ -1,7 +1,7 @@ package shield import ( - "github.com/garyburd/redigo/redis" + "github.com/gomodule/redigo/redis" "log" "strconv" )