はじめに
先日からAzure Cache for Redisのベストプラクティスを検証しています。
Azure Cache for Redisのドキュメントを見ていると、「接続の回復力に関するベストプラクティス」というドキュメントを見つけました。
以前、Spring BootアプリからAzure Cache for Redisへの接続をするためのブログ記事を載せたのですが、それをもう少し発展させてより有益な情報としていきたいと思います。
これまでのエントリーは以下のものです。
- Azure Cache for RedisのベストプラクティスをSpring Bootで検証する - miyohide's blog
- Azure Cache for RedisのベストプラクティスをSpring Bootで検証する(2) - miyohide's blog
前回の疑問解決
spring.redis.connect-timeout
の単位は何か?
前回中途半端になっていたものを解決していきます。spring.redis.connect-timeout
の単位です。
Spring Boot 2.6.1の場合、spring.redis.connect-timeout
の設定をしているのが以下のところです。
Spring Bootの機能でプロパティとして設定しているDuration
のデフォルト単位はミリ秒です。
このため、spring.redis.connect-timeout
の単位はミリ秒です。
spring.redis.timeout
の単位は何か?
同様にspring.redis.timeout
の単位を調べます。
Spring Boot 2.6.1の場合、spring.redis.timeout
の設定をしているのが以下のところです。
先程のspring.redis.connect-timeout
と同様にSpring Bootの機能でプロパティとして設定しているDuration
のデフォルト単位はミリ秒なので、spring.redis.connect-timeout
の単位はミリ秒です。
具体的な設定値
以上を踏まえて、Azure Cache for Redisのドキュメントにある設定値を指定してみます。下記ドキュメントには、接続タイムアウトは5秒、コマンドタイムアウトは5秒未満が推奨だそうです。
application.properties
には以下の設定をすれば良さそうです。
# connect-timeoutはRedisの接続タイムアウト時間 spring.redis.connect-timeout=5000 # timeoutはRedisの各コマンドのタイムアウト時間 spring.redis.timeout=4500
あまり進捗がありませんが、今日はここまで。