Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Shutdown client resources automatically #30

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions modules/celtuce-core/src/celtuce/connector.clj
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@
(.computationThreadPoolSize (:nb-worker-threads options-map)))
(.build builder)))

(defn destroy-client-resource
"If you create a client resource, you must close/dispose it; otherwise you will not
shutdown the Netty threads."
(defn ^:deprecated destroy-client-resource
"Generally you don't need to invoke this anymore in your applications;
client resources passed as options are now automatically shutdown as part of the `#'shutdown` protocol method."
[^ClientResources client-resources]
(.shutdown client-resources 100 1000 TimeUnit/MILLISECONDS))

Expand All @@ -247,7 +247,8 @@
^StatefulRedisConnection stateful-conn
conn-options
^RedisCodec codec
^RedisCommandFactory dynamic-factory]
^RedisCommandFactory dynamic-factory
^ClientResources client-resources]
RedisConnector
(commands-sync [_]
(locking clojure.lang.RT/REQUIRE_LOCK
Expand All @@ -261,7 +262,9 @@
(.reset stateful-conn))
(shutdown [_]
(.close stateful-conn)
(.shutdown redis-client)))
(.shutdown redis-client)
;; `some->`: for backwards compatibility
(some-> client-resources destroy-client-resource)))

(defn redis-server
[^String redis-uri &
Expand Down Expand Up @@ -293,7 +296,8 @@
:conn-options {:auto-flush auto-flush
:timeout conn-timeout
:unit conn-unit}
:dynamic-factory (RedisCommandFactory. stateful-conn)})))
:dynamic-factory (RedisCommandFactory. stateful-conn)
:client-resources client-resources})))

;;
;; Redis Cluster
Expand All @@ -305,7 +309,8 @@
^StatefulRedisClusterConnection stateful-conn
conn-options
^RedisCodec codec
^RedisCommandFactory dynamic-factory]
^RedisCommandFactory dynamic-factory
^ClientResources client-resources]
RedisConnector
(commands-sync [_]
(locking clojure.lang.RT/REQUIRE_LOCK
Expand All @@ -319,7 +324,9 @@
(.reset stateful-conn))
(shutdown [_]
(.close stateful-conn)
(.shutdown redis-client)))
(.shutdown redis-client)
;; `some->`: for backwards compatibility
(some-> client-resources destroy-client-resource)))

(defn redis-cluster
[^String redis-uri &
Expand Down Expand Up @@ -352,6 +359,7 @@
:conn-options {:auto-flush auto-flush
:timeout conn-timeout
:unit conn-unit}
:client-resources client-resources
:dynamic-factory (RedisCommandFactory. stateful-conn)})))

;;
Expand Down