Merge branch 'master' into better-error-handling-dyn

This commit is contained in:
Hossein Shafagh 2019-07-30 13:27:43 -07:00 committed by GitHub
commit 7810095796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -3,7 +3,9 @@ Helper Class for Redis
""" """
import redis import redis
import sys
from flask import current_app from flask import current_app
from lemur.extensions import sentry
from lemur.factory import create_app from lemur.factory import create_app
if current_app: if current_app:
@ -23,7 +25,19 @@ class RedisHandler:
def redis(self, db=0): def redis(self, db=0):
# The decode_responses flag here directs the client to convert the responses from Redis into Python strings # The decode_responses flag here directs the client to convert the responses from Redis into Python strings
# using the default encoding utf-8. This is client specific. # using the default encoding utf-8. This is client specific.
function = f"{__name__}.{sys._getframe().f_code.co_name}"
try:
red = redis.StrictRedis(host=self.host, port=self.port, db=self.db, encoding="utf-8", decode_responses=True) red = redis.StrictRedis(host=self.host, port=self.port, db=self.db, encoding="utf-8", decode_responses=True)
red.set("test", 0)
except redis.ConnectionError:
log_data = {
"function": function,
"message": "Redis Connection error",
"host": self.host,
"port": self.port
}
current_app.logger.error(log_data)
sentry.captureException()
return red return red