Skip to content

Commit

Permalink
[operation/fetch] Fixed specs
Browse files Browse the repository at this point in the history
  • Loading branch information
0exp committed Sep 2, 2018
1 parent 03e9cb6 commit 2d8c2da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions lib/any_cache/adapters/active_support_mem_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ def write(key, value, **options)
# @since 0.2.0
def increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
is_initial = !read(key) # TODO: rewrite with #exist?(key)

if is_initial
unless exist?(key)
write(key, amount, expires_in: expires_in) && amount
else
driver.increment(key, amount).tap do
Expand All @@ -96,9 +95,8 @@ def increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
# @since 0.2.0
def decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
is_initial = !read(key) # TODO: rewrite with #exist?(key)

if is_initial
unless exist?(key)
# NOTE: Dalli::Client can't decrement:
# - non-raw values;
# - values lower than zero;
Expand Down
6 changes: 2 additions & 4 deletions lib/any_cache/adapters/active_support_redis_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ def write(key, value, **options)
# @since 0.1.0
def increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
is_initial = exist?(key)

if is_initial
unless exist?(key)
write(key, amount, expires_in: expires_in) && amount
else
driver.increment(key, amount).tap do
Expand All @@ -90,9 +89,8 @@ def increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
# @since 0.1.0
def decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options)
expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
is_initial = exist?(key)

if is_initial
unless exist?(key)
write(key, -amount, expires_in: expires_in) && -amount
else
driver.decrement(key, amount).tap do
Expand Down

0 comments on commit 2d8c2da

Please sign in to comment.