mirror of https://github.com/zulip/zulip.git
Add helper function for returning a Redis client
(imported from commit 47f87d388d24343ac6b631181a55287eb8cd4a6d)
This commit is contained in:
parent
6ea795915e
commit
6691789cce
|
@ -1,6 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from django.conf import settings
|
||||
from zerver.lib.redis_utils import get_redis_client
|
||||
|
||||
import redis
|
||||
import time
|
||||
|
@ -11,7 +12,7 @@ from itertools import izip
|
|||
# Implement a rate-limiting scheme inspired by the one described here, but heavily modified
|
||||
# http://blog.domaintools.com/2013/04/rate-limiting-with-redis/
|
||||
|
||||
client = redis.StrictRedis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0)
|
||||
client = get_redis_client()
|
||||
rules = settings.RATE_LIMITING_RULES
|
||||
def _rules_for_user(user):
|
||||
if user.rate_limits != "":
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
import redis
|
||||
|
||||
def get_redis_client():
|
||||
return redis.StrictRedis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0)
|
|
@ -10,7 +10,6 @@ import tornado.ioloop
|
|||
import ujson
|
||||
import logging
|
||||
import time
|
||||
import redis
|
||||
|
||||
from zerver.models import UserProfile, get_user_profile_by_id, get_client
|
||||
from zerver.lib.queue import queue_json_publish
|
||||
|
@ -20,6 +19,7 @@ from zerver.lib.utils import statsd
|
|||
from zerver.lib.event_queue import get_client_descriptor
|
||||
from zerver.middleware import record_request_start_data, record_request_stop_data, \
|
||||
record_request_restart_data, write_log_line, format_timedelta
|
||||
from zerver.lib.redis_utils import get_redis_client
|
||||
|
||||
logger = logging.getLogger('zulip.socket')
|
||||
|
||||
|
@ -57,7 +57,7 @@ def register_connection(id, conn):
|
|||
def deregister_connection(conn):
|
||||
del connections[conn.client_id]
|
||||
|
||||
redis_client = redis.StrictRedis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0)
|
||||
redis_client = get_redis_client()
|
||||
|
||||
def req_redis_key(req_id):
|
||||
return 'socket_req_status:%s' % (req_id,)
|
||||
|
|
|
@ -22,6 +22,7 @@ from zerver.lib.socket import req_redis_key
|
|||
from confirmation.models import Confirmation
|
||||
from zerver.lib.db import reset_queries
|
||||
from django.core.mail import EmailMessage
|
||||
from zerver.lib.redis_utils import get_redis_client
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
@ -32,7 +33,6 @@ import time
|
|||
import datetime
|
||||
import logging
|
||||
import simplejson
|
||||
import redis
|
||||
import StringIO
|
||||
|
||||
def assign_queue(queue_name, enabled=True):
|
||||
|
@ -262,7 +262,7 @@ class SlowQueryWorker(QueueProcessingWorker):
|
|||
class MessageSenderWorker(QueueProcessingWorker):
|
||||
def __init__(self):
|
||||
super(MessageSenderWorker, self).__init__()
|
||||
self.redis_client = redis.StrictRedis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0)
|
||||
self.redis_client = get_redis_client()
|
||||
self.handler = BaseHandler()
|
||||
self.handler.load_middleware()
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ from django.template import RequestContext, loader
|
|||
|
||||
from zerver.decorator import has_request_variables, REQ, json_to_dict
|
||||
from zerver.lib.actions import internal_send_message
|
||||
from zerver.lib.redis_utils import get_redis_client
|
||||
from zerver.lib.response import json_success, json_error, json_response, json_method_not_allowed
|
||||
from zerver.lib.rest import rest_dispatch as _rest_dispatch
|
||||
from zerver.models import get_realm, get_user_profile_by_email, resolve_email_to_domain, \
|
||||
|
@ -16,11 +17,10 @@ from error_notify import notify_server_error, notify_browser_error
|
|||
from django.core.mail import send_mail
|
||||
from django.conf import settings
|
||||
import time
|
||||
import redis
|
||||
|
||||
rest_dispatch = csrf_exempt((lambda request, *args, **kwargs: _rest_dispatch(request, globals(), *args, **kwargs)))
|
||||
|
||||
client = redis.StrictRedis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0)
|
||||
client = get_redis_client()
|
||||
|
||||
def has_enough_time_expired_since_last_message(sender_email, min_delay):
|
||||
# This function returns a boolean, but it also has the side effect
|
||||
|
|
Loading…
Reference in New Issue