Singleton pattern will only generate an instance. The Redis pool needs to be initialized only once and the connection is obtained from the pool.
Signed-off-by: Wu Zhende wuzhende666@163.com --- src/scheduler/redis_client.cr | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/src/scheduler/redis_client.cr b/src/scheduler/redis_client.cr index 1253108..a8d9dcb 100644 --- a/src/scheduler/redis_client.cr +++ b/src/scheduler/redis_client.cr @@ -6,12 +6,17 @@ require "redis"
require "./constants" require "../lib/job" +require "singleton"
class Redis::Client class_property :client HOST = (ENV.has_key?("REDIS_HOST") ? ENV["REDIS_HOST"] : JOB_REDIS_HOST) PORT = (ENV.has_key?("REDIS_PORT") ? ENV["REDIS_PORT"] : JOB_REDIS_PORT).to_i32
+ def self.instance + Singleton::Of(self).instance + end + def initialize(host = HOST, port = PORT) @client = Redis::PooledClient.new(host: host, port: port, pool_size: 25, pool_timeout: 0.01) end
On Thu, Jan 28, 2021 at 07:29:44PM +0800, Wu Zhende wrote:
Singleton pattern will only generate an instance. The Redis pool needs to be initialized only once and the connection is obtained from the pool.
how did you find it from scheduler log: error writing to socket ?
Thanks, Shenwei
Signed-off-by: Wu Zhende wuzhende666@163.com
src/scheduler/redis_client.cr | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/src/scheduler/redis_client.cr b/src/scheduler/redis_client.cr index 1253108..a8d9dcb 100644 --- a/src/scheduler/redis_client.cr +++ b/src/scheduler/redis_client.cr @@ -6,12 +6,17 @@ require "redis"
require "./constants" require "../lib/job" +require "singleton"
class Redis::Client class_property :client HOST = (ENV.has_key?("REDIS_HOST") ? ENV["REDIS_HOST"] : JOB_REDIS_HOST) PORT = (ENV.has_key?("REDIS_PORT") ? ENV["REDIS_PORT"] : JOB_REDIS_PORT).to_i32
- def self.instance
- Singleton::Of(self).instance
- end
- def initialize(host = HOST, port = PORT) @client = Redis::PooledClient.new(host: host, port: port, pool_size: 25, pool_timeout: 0.01) end
-- 2.23.0