Last active
September 19, 2024 12:37
-
-
Save gradetwo/5962997 to your computer and use it in GitHub Desktop.
Connection Pool in redis python client redis-py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentRedis(RedisStorage): | |
def add_comment(self, checkin_id, comment_id, comment_data): | |
r_client = self._get_db("COMMENT") | |
# u can use redis now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
remember call setup_redis_pool when app init