-
Notifications
You must be signed in to change notification settings - Fork 2
update pool-config: document all supported config keys in README, clarify inheritance and defaults usage #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,6 @@ RQ (Redis Queue) is a simple Clojure package for queueing jobs and processing th | |
|
|
||
| We distribute the library via [Clojars](https://clojars.org/com.moclojer/rq). | ||
|
|
||
|
|
||
| [](https://clojars.org/com.moclojer/rq) | ||
|
|
||
| ```edn | ||
|
|
@@ -166,7 +165,35 @@ The `clj-rq` library provides a set of pub/sub functions that facilitate message | |
| ```clojure | ||
| (rq-pubsub/unarquive-channel! client "my-channel") | ||
| ``` | ||
|
|
||
|
|
||
| ### pool configuration | ||
|
|
||
| `rq/create-client` applies a tuned `GenericObjectPoolConfig` by default (`maxTotal` 128, `minIdle` 16, health checks enabled, etc.). | ||
| You can override these settings by passing an options map as the second argument. | ||
|
|
||
| ```clojure | ||
| (def *redis-pool* | ||
| (rq/create-client "redis://localhost:6379/0" | ||
| {:pool-config {:max-total 64 | ||
| :max-wait-ms 2_000 | ||
| :test-on-borrow false}})) | ||
|
Comment on lines
+177
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the numeric literal example. Clojure’s reader still rejects digit separators like 🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, send update commit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @avelino, here's the corrected code for the pool configuration example: (def *redis-pool*
(rq/create-client "redis://localhost:6379/0"
{:pool-config {:max-total 64
:max-wait-ms 2000
:test-on-borrow false}}))The numeric literal has been changed from 🧠 Learnings used |
||
| ``` | ||
|
|
||
| Supported keys inside `:pool-config` include: | ||
|
|
||
| - `:max-total`, `:max-idle`, `:min-idle` | ||
| - `:max-wait-ms`, `:time-between-eviction-runs-ms`, `:min-evictable-idle-ms`, `:soft-min-evictable-idle-ms` | ||
| - `:test-on-borrow`, `:test-on-return`, `:test-on-create`, `:test-while-idle` | ||
| - `:num-tests-per-eviction-run`, `:block-when-exhausted`, `:fairness`, `:lifo` | ||
| - `:jmx-enabled`, `:jmx-name-base`, `:jmx-name-prefix`, `:eviction-policy-class-name`, `:evictor-shutdown-timeout-ms` | ||
|
|
||
| To skip the tuned defaults and rely on Jedis' own configuration, use `:pool-config :skip`. | ||
| If you want to set values without inheriting the defaults, add `{:inherit-defaults? false ...}` to the `:pool-config` map. | ||
|
|
||
| ```clojure | ||
| (rq/create-client "redis://localhost:6379/0" {:pool-config :skip}) | ||
| ``` | ||
|
|
||
| ## complete example | ||
|
|
||
| ```clojure | ||
|
|
@@ -234,7 +261,7 @@ sequenceDiagram | |
| User->>Client: close-client client | ||
| Client-->>Logger: log closing client | ||
| Client-->>User: confirm client closure | ||
| ``` | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,60 @@ | ||
| (ns com.moclojer.rq-test | ||
| (:require | ||
| [clojure.test :as t] | ||
| [com.moclojer.rq :as rq])) | ||
| [com.moclojer.rq :as rq]) | ||
| (:import | ||
| [org.apache.commons.pool2.impl GenericObjectPoolConfig])) | ||
|
|
||
| ;; WARNING: redis needs to be runing. | ||
| ;; WARNING: redis needs to be running. | ||
| (t/deftest create-client-test | ||
| (t/testing "redis-client being created" | ||
| (let [client (rq/create-client "redis://localhost:6379")] | ||
| (t/is (.. @client getPool getResource)) | ||
| (rq/close-client client)))) | ||
|
|
||
| (t/deftest pool-config-resolution-test | ||
| (t/testing "default settings are applied" | ||
| (let [^GenericObjectPoolConfig cfg (#'rq/resolve-pool-config nil)] | ||
| (t/is (= 128 (.getMaxTotal cfg))) | ||
| (t/is (= 128 (.getMaxIdle cfg))) | ||
| (t/is (= 16 (.getMinIdle cfg))) | ||
| (t/is (= 1000 (.getMaxWaitMillis cfg))) | ||
| (t/is (.getTestOnBorrow cfg)) | ||
| (t/is (.getTestOnReturn cfg)) | ||
| (t/is (.getTestOnCreate cfg)) | ||
| (t/is (.getTestWhileIdle cfg)) | ||
| (t/is (= 60000 (.getMinEvictableIdleTimeMillis cfg))) | ||
| (t/is (= 60000 (.getSoftMinEvictableIdleTimeMillis cfg))) | ||
| (t/is (= 30000 (.getTimeBetweenEvictionRunsMillis cfg))) | ||
| (t/is (= 3 (.getNumTestsPerEvictionRun cfg))) | ||
| (t/is (.getBlockWhenExhausted cfg)))) | ||
|
|
||
| (t/testing "custom overrides keep defaults" | ||
| (let [^GenericObjectPoolConfig cfg (#'rq/resolve-pool-config {:max-total 64 | ||
| :max-wait-ms 2500})] | ||
| (t/is (= 64 (.getMaxTotal cfg))) | ||
| (t/is (= 2500 (.getMaxWaitMillis cfg))) | ||
| (t/is (= 16 (.getMinIdle cfg))))) | ||
|
|
||
| (t/testing "custom overrides without defaults" | ||
| (let [^GenericObjectPoolConfig cfg (#'rq/resolve-pool-config {:inherit-defaults? false | ||
| :max-total 10})] | ||
| (t/is (= 10 (.getMaxTotal cfg))) | ||
| (t/is (not (.getTestOnBorrow cfg))))) | ||
|
|
||
| (t/testing "returning an instance as-is" | ||
| (let [cfg (doto (GenericObjectPoolConfig.) | ||
| (.setMaxTotal 5))] | ||
| (t/is (identical? cfg (#'rq/resolve-pool-config cfg))))) | ||
|
|
||
| (t/testing "skip configuration" | ||
| (t/is (nil? (#'rq/resolve-pool-config :skip))))) | ||
|
|
||
| (t/deftest create-client-with-options-test | ||
| (t/testing "create-client accepts option map" | ||
| (let [client (rq/create-client "redis://localhost:6379" | ||
| {:pool-config :skip})] | ||
| (t/is (instance? clojure.lang.Atom client)) | ||
| (rq/close-client client)))) | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'unarquive' to 'unarchive'.