Class: Query

Inherits:
Object
  • Object
show all
Defined in:
lib/redisant/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(criteria) ⇒ Query

Returns a new instance of Query.



3
4
5
# File 'lib/redisant/query.rb', line 3

def initialize criteria
  @criteria = criteria
end

Instance Method Details

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/redisant/query.rb', line 7

def run
  raise "Count and random cannot be combined" if @criteria.count? && @criteria.random?
  
  collect_keys
  if @criteria.count?
    return count
  elsif @criteria.random?
    random
  else
    fetch
  end

  if @criteria.criteria[:exists]
    any?
  elsif @criteria.ids?
    flatten_single_items @ids
  else
    load_objects
    flatten_single_items @objects
  end
ensure
  delete_tmp
end