Class: AnyCache::Adapters::Redis Private
- Defined in:
- lib/any_cache/adapters/redis.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Constant Summary collapse
- NO_EXPIRATION_TTL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
nil- DEAD_TTL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
0- DEFAULT_INCR_DECR_AMOUNT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
1
Instance Attribute Summary
Attributes inherited from Basic
Class Method Summary collapse
Instance Method Summary collapse
- #clear(**options) ⇒ void private
- #decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ NillClass, Integer private
- #delete(key, **options) ⇒ void private
- #exist?(key, **options) ⇒ Boolean private
- #expire(key, expires_in: DEAD_TTL) ⇒ void private
- #fetch(key, **options) ⇒ Object private
- #increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ NilClass, Integer private
- #persist(key, **options) ⇒ void private
- #read(key, **options) ⇒ Object private
- #write(key, value, **options) ⇒ void private
Methods inherited from Basic
Constructor Details
This class inherits a constructor from AnyCache::Adapters::Basic
Class Method Details
.supported_driver?(driver) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/any_cache/adapters/redis.rb', line 13 def supported_driver?(driver) AnyCache::Drivers::Redis.supported_source?(driver) end |
Instance Method Details
#clear(**options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
146 147 148 |
# File 'lib/any_cache/adapters/redis.rb', line 146 def clear(**) flushdb end |
#decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ NillClass, Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/any_cache/adapters/redis.rb', line 107 def decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) new_amount = nil pipelined do new_amount = decrby(key, amount) expire(key, expires_in: expires_in) if expires_in end new_amount&.value end |
#delete(key, **options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
77 78 79 |
# File 'lib/any_cache/adapters/redis.rb', line 77 def delete(key, **) del(key) end |
#exist?(key, **options) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
156 157 158 |
# File 'lib/any_cache/adapters/redis.rb', line 156 def exist?(key, **) exists(key) end |
#expire(key, expires_in: DEAD_TTL) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
125 126 127 128 129 |
# File 'lib/any_cache/adapters/redis.rb', line 125 def expire(key, expires_in: DEAD_TTL) expires_in ||= DEAD_TTL unless expires_in driver.expire(key, expires_in) end |
#fetch(key, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
167 168 169 170 171 172 173 174 175 |
# File 'lib/any_cache/adapters/redis.rb', line 167 def fetch(key, **) force_rewrite = .fetch(:force, false) force_rewrite = force_rewrite.call if force_rewrite.respond_to?(:call) # NOTE: think about #pipelined read(key).tap { |value| return value if value } unless force_rewrite yield.tap { |value| write(key, value, **) } if block_given? end |
#increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ NilClass, Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/any_cache/adapters/redis.rb', line 88 def increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) new_amount = nil pipelined do new_amount = incrby(key, amount) expire(key, expires_in: expires_in) if expires_in end new_amount&.value end |
#persist(key, **options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
137 138 139 |
# File 'lib/any_cache/adapters/redis.rb', line 137 def persist(key, **) driver.persist(key) end |
#read(key, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/any_cache/adapters/redis.rb', line 54 def read(key, **) get(key) end |
#write(key, value, **options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
65 66 67 68 69 |
# File 'lib/any_cache/adapters/redis.rb', line 65 def write(key, value, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) expires_in ? setex(key, expires_in, value) : set(key, value) end |