Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gradetwo
Last active February 19, 2023 06:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gradetwo/5962997 to your computer and use it in GitHub Desktop.
Save gradetwo/5962997 to your computer and use it in GitHub Desktop.
Connection Pool in redis python client redis-py
import redis
class RedisStorage(object):
_redis_pool = {}
@classmethod
def setup_redis_pool(cls, redis_pool):
for k, v in redis_pool.iteritems():
cls._redis_pool[k] = redis.Redis(v[0], v[1])
def _get_db(self, db_name):
return self._redis_pool.get(db_name, None)
class CommentRedis(RedisStorage):
def add_comment(self, checkin_id, comment_id, comment_data):
r_client = self._get_db("COMMENT")
# u can use redis now
@gradetwo
Copy link
Author

remember call setup_redis_pool when app init

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment