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
- DELETE_MATCHED_CURSOR_START =
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'
- DELETE_MATCHED_BATCH_SIZE =
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.
10
Instance Attribute Summary
Attributes inherited from Basic
Class Method Summary collapse
Instance Method Summary collapse
- #cleanup(**options) ⇒ void private
- #clear(**options) ⇒ void private
- #decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ NillClass, Integer private
- #delete(key, **options) ⇒ void private
- #delete_matched(pattern, **options) ⇒ void private
- #exist?(key, **options) ⇒ Boolean private
- #expire(key, expires_in: DEAD_TTL) ⇒ void private
- #fetch(key, **options, &fallback) ⇒ Object private
- #fetch_multi(*keys, **options, &fallback) ⇒ Hash private
- #increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ NilClass, Integer private
- #persist(key, **options) ⇒ void private
- #read(key, **options) ⇒ Object private
- #read_multi(*keys, **options) ⇒ Hash private
- #write(key, value, **options) ⇒ void private
- #write_multi(entries, **options) ⇒ void private
Methods inherited from Basic
Methods included from Dumper::InterfaceAccessMixin
#detransform_pairset, #detransform_value, #transform_pairset, #transform_value
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
#cleanup(**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.
258 259 260 |
# File 'lib/any_cache/adapters/redis.rb', line 258 def cleanup(**) # NOTE: manual removing is not suppored (redis doing this by itself) end |
#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.
249 250 251 |
# File 'lib/any_cache/adapters/redis.rb', line 249 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.
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/any_cache/adapters/redis.rb', line 210 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.
155 156 157 |
# File 'lib/any_cache/adapters/redis.rb', line 155 def delete(key, **) del(key) end |
#delete_matched(pattern, **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.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/any_cache/adapters/redis.rb', line 165 def delete_matched(pattern, **) cursor = DELETE_MATCHED_CURSOR_START case pattern when String loop do cursor, keys = scan(cursor, match: pattern, count: DELETE_MATCHED_BATCH_SIZE) del(keys) break if cursor == DELETE_MATCHED_CURSOR_START end when Regexp loop do cursor, keys = scan(cursor, count: DELETE_MATCHED_BATCH_SIZE) del(keys.grep(pattern)) break if cursor == DELETE_MATCHED_CURSOR_START end end 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.
268 269 270 |
# File 'lib/any_cache/adapters/redis.rb', line 268 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.
228 229 230 231 232 |
# File 'lib/any_cache/adapters/redis.rb', line 228 def expire(key, expires_in: DEAD_TTL) expires_in ||= DEAD_TTL unless expires_in driver.expire(key, expires_in) end |
#fetch(key, **options, &fallback) ⇒ 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.
125 126 127 128 129 130 131 132 133 |
# File 'lib/any_cache/adapters/redis.rb', line 125 def fetch(key, **, &fallback) force_rewrite = .fetch(:force, false) force_rewrite = force_rewrite.call(key) if force_rewrite.respond_to?(:call) # NOTE: think about #pipelined read(key, **).tap { |value| return value if value } unless force_rewrite yield(key).tap { |value| write(key, value, **) } if block_given? end |
#fetch_multi(*keys, **options, &fallback) ⇒ Hash
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.
142 143 144 145 146 147 |
# File 'lib/any_cache/adapters/redis.rb', line 142 def fetch_multi(*keys, **, &fallback) # TODO: think about multi-thread approach keys.each_with_object({}) do |key, dataset| dataset[key] = fetch(key, **, &fallback) end 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.
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/any_cache/adapters/redis.rb', line 191 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.
240 241 242 |
# File 'lib/any_cache/adapters/redis.rb', line 240 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.
69 70 71 72 73 74 |
# File 'lib/any_cache/adapters/redis.rb', line 69 def read(key, **) value = get(key) raw = .fetch(:raw, false) raw ? value : detransform_value(value) end |
#read_multi(*keys, **options) ⇒ Hash
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.
82 83 84 85 86 87 |
# File 'lib/any_cache/adapters/redis.rb', line 82 def read_multi(*keys, **) raw = .fetch(:raw, false) entries = mapped_mget(*keys) raw ? entries : detransform_pairset(entries) 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.
97 98 99 100 101 102 103 |
# File 'lib/any_cache/adapters/redis.rb', line 97 def write(key, value, **) raw = .fetch(:raw, false) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) value = transform_value(value) unless raw expires_in ? setex(key, expires_in, value) : set(key, value) end |
#write_multi(entries, **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.
111 112 113 114 115 116 |
# File 'lib/any_cache/adapters/redis.rb', line 111 def write_multi(entries, **) raw = .fetch(:raw, false) entries = transform_pairset(entries) unless raw mapped_mset(entries) end |