Mod Carmine appender to work correctly with Carmine v3+

This commit is contained in:
Peter Taoussanis 2014-03-09 17:46:15 +07:00
parent f8ab8abc42
commit 338ac0497d
2 changed files with 28 additions and 24 deletions

View File

@ -1,8 +1,11 @@
## v3.1.2 / 2014 Mar 9
* FIX: Carmine appender unfreezable support for Carmine v3+.
## v3.1.1 / 2014 Feb 26
### Fixes
* Fix project.clj to prevent unnecessary downstream deps.
* FIX: project.clj to prevent unnecessary downstream deps.
## v3.1.0 / 2014 Feb 23

View File

@ -59,29 +59,30 @@
nmax-entries (nentries-by-level level)]
(when (> nmax-entries 0)
(car/wcar (or conn-opts (:conn opts)) ; :conn is Deprecated
(binding [nippy/*final-freeze-fallback* nippy/freeze-fallback-as-str]
(car/hset k-hash entry-hash entry))
(car/zadd k-zset udt entry-hash)
(binding [nippy/*final-freeze-fallback* nippy/freeze-fallback-as-str]
(car/wcar (or conn-opts (:conn opts)) ; :conn is Deprecated
(when (< (rand) 0.01) ; Occasionally GC
;; This is necessary since we're doing zset->entry-hash->entry
;; rather than zset->entry. We want the former for the control
;; it gives us over what should constitute a 'unique' entry.
(car/lua
"-- -ive idx used to prune from the right (lowest score first)
local max_idx = (0 - (tonumber(_:nmax-entries)) - 1)
local entries_to_prune =
redis.call('zrange', _:k-zset, 0, max_idx)
redis.call('zremrangebyrank', _:k-zset, 0, max_idx) -- Prune zset
(car/hset k-hash entry-hash entry)
(car/zadd k-zset udt entry-hash)
for i,entry in pairs(entries_to_prune) do
redis.call('hdel', _:k-hash, entry) -- Prune hash
end
return nil"
{:k-zset k-zset
:k-hash k-hash}
{:nmax-entries nmax-entries}))))))})))
(when (< (rand) 0.01) ; Occasionally GC
;; This is necessary since we're doing zset->entry-hash->entry
;; rather than zset->entry. We want the former for the control
;; it gives us over what should constitute a 'unique' entry.
(car/lua
"-- -ive idx used to prune from the right (lowest score first)
local max_idx = (0 - (tonumber(_:nmax-entries)) - 1)
local entries_to_prune =
redis.call('zrange', _:k-zset, 0, max_idx)
redis.call('zremrangebyrank', _:k-zset, 0, max_idx) -- Prune zset
for i,entry in pairs(entries_to_prune) do
redis.call('hdel', _:k-hash, entry) -- Prune hash
end
return nil"
{:k-zset k-zset
:k-hash k-hash}
{:nmax-entries nmax-entries})))))))})))
;;;; Query utils