Module: Picky::Backends::Redis::NonScripting
- Defined in:
- lib/picky/backends/redis.rb
Overview
Does not use Lua scripting, < Redis 2.6.
Instance Method Summary collapse
Instance Method Details
#ids(combinations, amount, offset) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/picky/backends/redis.rb', line 262 def ids combinations, amount, offset identifiers = identifiers_for combinations result_id = generate_intermediate_result_id # Little optimization. # if identifiers.size > 1 # Intersect and store. # intersected = client.zinterstore result_id, identifiers # Return clean and early if there has been no intersection. # if intersected.zero? client.del result_id return [] end # Get the stored result. # results = client.zrange result_id, offset, (offset + amount) # Delete the stored result as it was only for temporary purposes. # # Note: I could also not delete it, but that # would not be clean at all. # client.del result_id else results = client.zrange identifiers.first, offset, (offset + amount) end results end |