Skip to content
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

Replace lua code by set function call #313

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ And as always **please report any unexpected problems** - thank you! 🙏
> **Dep**: Carmine is [on Clojars](https://clojars.org/com.taoensso/carmine/versions/3.4.0).
> **Versioning**: Carmine uses [Break Versioning](https://www.taoensso.com/break-versioning).

This is a **maintenance release** that should be **non-breaking** for most users.
This is a **security and maintenance release** that should be **non-breaking** for most users.

The release **updates Carmine's Nippy version** from `v3.3.0` to `v3.4.2`. Please review the [relevant Nippy release info](https://github.com/taoensso/nippy/releases/tag/v3.4.2), and **ensure adequate testing** in your environment before updating production data.
⚠️ It addresses a [**security vulnerability**](https://github.com/taoensso/nippy/security/advisories/GHSA-vw78-267v-588h) in [Nippy](https://www.taoensso.com/nippy)'s upstream compression library and is **recommended for all existing users**. Please review the [relevant Nippy release info](https://github.com/taoensso/nippy/releases/tag/v3.4.2), and **ensure adequate testing** in your environment before updating production data.

And as always **please report any unexpected problems** - thank you! 🙏

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Carmine is a mature Redis client for Clojure that offers an idiomatic Clojure AP

## Latest release/s

- `2024-05-30` `v3.4.1`: [release info](../../releases/tag/v3.4.1)
- `2024-05-30` `v3.4.1`: [release info](../../releases/tag/v3.4.1) (⚠️ v3.4.0+ contains [**security fix**](https://github.com/taoensso/nippy/security/advisories/GHSA-vw78-267v-588h))

[![Main tests][Main tests SVG]][Main tests URL]
[![Graal tests][Graal tests SVG]][Graal tests URL]
Expand Down
71 changes: 71 additions & 0 deletions carmine-v4.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#+TITLE: Title
#+STARTUP: indent overview hidestars
#+TAGS: { Cost: c1(1) c2(2) c3(3) c4(4) c5(5) }
#+TAGS: nb(n) urgent(u)

* Next
** Re-eval choice to switch away from KeyedObjectPool
** Review arch needs for Cluster, esp. re: conns

** Add SSB stats to pooled manager (borrow time, etc.)?
** Add SSB stats to Sentinel?
** Common & core util to parse-?marked-ba -> [<kind> <payload>]
** Some way to implement a parser over >1 replies?
E.g. fetch two sets, and parser to merge -> single reply

* Later
** New Pub/Sub API? (note RESP2 vs RESP3 differences)
Pub/Sub + Sentinel integration
psubscribe* to Sentinel server
check for `switch-master` channel name
"switch-master" <master-name> <old-ip> <old-port> <new-ip> <new-port>

** Implement Cluster (enough user demand?)
** Use Telemere (shell API?)

* Polish
** Print methods, toString content, etc.
** Check all errors: eids, messages, data, cbids
** Check all dynamic bindings and sys-vals, ensure accessible
** Document `*default-conn-opts*`, incl. cbs
** Document `*default-sentinel-opts*`, incl. cbs
** Complete (esp. high-level / integration) tests
** Review all config, docstring, privacy, etc.
** Grep for TODOs

* Refactor commands
** Add modules support
** Support custom (e.g. newer) commands.json or edn
** Refactor helpers API, etc.
** Modern Tundra?
** Further MQ improvements?

* Release
** v4 upgrade/migration plan
** v4 wiki with changes, migration, new features, examples, etc.
** First public alpha

* CHANGELOG
** [new] Full RESP3 support, incl. streaming, etc.
*** Enabled by default, requires Redis >= v6 (2020-04-30).
** [new] Full Redis Sentinel support - incl. auto failover and read replicas.
** [mod] Hugely improved connections API, incl. improved:
*** Flexibility
*** Docs
*** Usability (e.g. opts validation, hard shutdowns, closing managed conns, etc.).
*** Transparency (deref stats, cbs, timings for profiling, etc.).
**** Derefs: Conns, ConnManagers, SentinelSpecs.
*** Protocols for extension by advanced users.
*** Full integration with Sentinel, incl.:
**** Auto invalidation of pool conns on master changes.
**** Auto verification of addresses on pool borrows.
*** [new] Common conn utils are now aliased in core Carmine ns for convenience.
*** [new] Improved pool efficiency, incl. smarter sub-pool keying.
*** [mod] Improved parsing API, incl.:
**** General simplifications.
**** Aggregate parsers, with xform support.
*** [new] *auto-serialize?*, *auto-deserialize?*
*** [new] Greatly improved `skip-replies` performance
*** [mod] Simplified parsers API
*** [new] Improvements to docs, error messages, debug data, etc.
*** [new] New Wiki with further documentation and examples.
7 changes: 6 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.taoensso/carmine "3.4.1"
(defproject com.taoensso/carmine "3.5.0-SNAPSHOT"
:author "Peter Taoussanis <https://www.taoensso.com>"
:description "Redis client + message queue for Clojure"
:url "https://github.com/taoensso/carmine"
Expand Down Expand Up @@ -56,11 +56,16 @@
{:language #{:clojure #_:clojurescript}
:base-language :clojure}}}

:test-selectors
{:v3 (fn [{:keys [ns]} & _] (.startsWith (str ns) "taoensso.carmine."))
:v4 (fn [{:keys [ns]} & _] (.startsWith (str ns) "taoensso.carmine-v4."))}

:aliases
{"start-dev" ["with-profile" "+dev" "repl" ":headless"]
;; "build-once" ["do" ["clean"] ["cljsbuild" "once"]]
"deploy-lib" ["do" #_["build-once"] ["deploy" "clojars"] ["install"]]

"test-v4" ["with-profile" "+c1.12:+c1.11:+c1.10:+c1.9" "test" ":v4"]
"test-clj" ["with-profile" "+c1.12:+c1.11:+c1.10:+c1.9" "test"]
;; "test-cljs" ["with-profile" "+c1.12" "cljsbuild" "test"]
"test-all" ["do" ["clean"] ["test-clj"] #_["test-cljs"]]})
15 changes: 3 additions & 12 deletions src/taoensso/carmine/locks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,15 @@

(defn acquire-lock
"Attempts to acquire a distributed lock, returning an owner UUID iff successful."
;; TODO Waiting on http://goo.gl/YemR7 for simpler (non-Lua) solution
[conn-opts lock-name timeout-ms wait-ms]
(let [max-udt (+ wait-ms (System/currentTimeMillis))
uuid (str (java.util.UUID/randomUUID))]
(wcar conn-opts ; Hold one connection for all attempts
(loop []
(when (> max-udt (System/currentTimeMillis))
(if (-> (car/lua
"if redis.call('setnx', _:lkey, _:uuid) == 1 then
redis.call('pexpire', _:lkey, _:timeout-ms);
return 1;
else
return 0;
end"
{:lkey (lkey lock-name)}
{:uuid uuid
:timeout-ms timeout-ms})
car/with-replies car/as-bool)
(if (-> (car/set (lkey lock-name) uuid "nx" "px" timeout-ms)
(car/with-replies)
(= "OK"))
(car/return uuid)
(do (Thread/sleep 1) (recur))))))))

Expand Down
12 changes: 8 additions & 4 deletions src/taoensso/carmine/message_queue.clj
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,15 @@

java.io.Closeable (close [this] (stop this))
Object
(toString [this] ; "CarmineMessageQueueWorker[nthreads=1w+1h, running]"
(str "CarmineMessageQueueWorker[qname=" qname ", nthreads="
(toString [this]
;; "CarmineMessageQueueWorker[qname=foo nthreads=1w+1h running 0x7b9f6831]"
(str "CarmineMessageQueueWorker["
"qname=" qname " "
"nthreads="
(get worker-opts :nthreads-worker) "w+"
(get worker-opts :nthreads-handler) "h, "
(if @running?_ "running" "shut down") "]"))
(get worker-opts :nthreads-handler) "h "
(if @running?_ "running" "shut down") " "
(enc/ident-hex-str this) "]"))

clojure.lang.IDeref
(deref [this]
Expand Down
Loading