Commit 5af9c5c206a7d62b2a990be7b7687219724432ae

Authored by Andrew Kane
1 parent 4f3e6b4a

DRY redis code [skip ci]

Showing 1 changed file with 7 additions and 3 deletions   Show diff stats
lib/searchkick/index.rb
@@ -255,7 +255,7 @@ module Searchkick @@ -255,7 +255,7 @@ module Searchkick
255 255
256 if batch 256 if batch
257 import_or_update scope.to_a, method_name, async, delete_missing, record_ids, scope.model_name.name.constantize 257 import_or_update scope.to_a, method_name, async, delete_missing, record_ids, scope.model_name.name.constantize
258 - Searchkick.redis.srem(batches_key, batch_id) if batch_id && Searchkick.redis 258 + redis.srem(batches_key, batch_id) if batch_id && redis
259 elsif full && async 259 elsif full && async
260 if scope.respond_to?(:primary_key) 260 if scope.respond_to?(:primary_key)
261 # TODO expire Redis key 261 # TODO expire Redis key
@@ -274,7 +274,7 @@ module Searchkick @@ -274,7 +274,7 @@ module Searchkick
274 index_name: name, 274 index_name: name,
275 batch_id: batch_id 275 batch_id: batch_id
276 ) 276 )
277 - Searchkick.redis.sadd(batches_key, batch_id) if Searchkick.redis 277 + redis.sadd(batches_key, batch_id) if redis
278 end 278 end
279 else 279 else
280 raise Searchkick::Error, "async option only supported for ActiveRecord" 280 raise Searchkick::Error, "async option only supported for ActiveRecord"
@@ -310,7 +310,7 @@ module Searchkick @@ -310,7 +310,7 @@ module Searchkick
310 end 310 end
311 311
312 def batches_left 312 def batches_left
313 - Searchkick.redis.scard(batches_key) if Searchkick.redis 313 + redis.scard(batches_key) if redis
314 end 314 end
315 315
316 # other 316 # other
@@ -469,6 +469,10 @@ module Searchkick @@ -469,6 +469,10 @@ module Searchkick
469 end 469 end
470 end 470 end
471 471
  472 + def redis
  473 + Searchkick.redis
  474 + end
  475 +
472 # use bulk if no callbacks value set 476 # use bulk if no callbacks value set
473 def possibly_bulk 477 def possibly_bulk
474 if Searchkick.callbacks_value 478 if Searchkick.callbacks_value