LoginSignup
7
8

More than 5 years have passed since last update.

redis.pyのConnectionPoolの実装よんだ

Last updated at Posted at 2013-09-11

利用できるコネクションと使ってるコネクション

_available_connections で利用できるコネクションのlist
_created_connections で今まで作ったコネクションの総数
_in_use_connection で今使っているコネクションのset

get_connectionメソッドで_available_connectionsから利用できるコネクションがあればpopでとってくる。ないならmake_connectionで新規コネクションをつくり、_in_use_connectionにaddする

releaseメソッドでコネクションをpookに返却する。(_in_use_connectionからremoveし、_available_connectionsとappend)

disconnectでpoolの開放

実際でどうつかわれるかは

StrictRedisクラスのexecute_commandメソッドで
poolからget_connectionメソッドでコネクションを取得
コネクションを利用してコマンドを実行し、コマンドの実行が正常でも異常でも終了したら(finally)releaseでコネクションを返す(異常の場合はpoolからのコネクションを破棄し、新しいコネクションを生成)

ふぅ

7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8