Class: Relix::OrderedIndex::QueryClause
- Inherits:
-
Object
- Object
- Relix::OrderedIndex::QueryClause
- Defined in:
- lib/relix/indexes/ordered.rb
Instance Method Summary collapse
- #eq(value) ⇒ Object
- #gt(value) ⇒ Object
- #gte(value) ⇒ Object
-
#initialize(redis, index) ⇒ QueryClause
constructor
A new instance of QueryClause.
- #limit(value) ⇒ Object
- #lookup ⇒ Object
- #lt(value) ⇒ Object
- #lte(value) ⇒ Object
- #offset(value) ⇒ Object
- #order(value) ⇒ Object
- #zrangebyscore_limit ⇒ Object
Constructor Details
#initialize(redis, index) ⇒ QueryClause
Returns a new instance of QueryClause.
31 32 33 34 |
# File 'lib/relix/indexes/ordered.rb', line 31 def initialize(redis, index) @redis, @index = redis, index @lt, @gt, @limit, @offset, @order = '+inf', '-inf', nil, nil, :asc end |
Instance Method Details
#eq(value) ⇒ Object
56 57 58 59 |
# File 'lib/relix/indexes/ordered.rb', line 56 def eq(value) lte(value) gte(value) end |
#gt(value) ⇒ Object
46 47 48 49 |
# File 'lib/relix/indexes/ordered.rb', line 46 def gt(value) @gt = "(#{@index.score_for_value(value)}" self end |
#gte(value) ⇒ Object
51 52 53 54 |
# File 'lib/relix/indexes/ordered.rb', line 51 def gte(value) @gt = @index.score_for_value(value) self end |
#limit(value) ⇒ Object
70 71 72 73 |
# File 'lib/relix/indexes/ordered.rb', line 70 def limit(value) @limit = value self end |
#lookup ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/relix/indexes/ordered.rb', line 87 def lookup command, score_1, score_2 = case @order when :desc then [:zrevrangebyscore, @lt, @gt] when :asc then [:zrangebyscore, @gt, @lt] end @redis.send(command, @index.sorted_set_name, score_1, score_2, limit: zrangebyscore_limit) end |
#lt(value) ⇒ Object
36 37 38 39 |
# File 'lib/relix/indexes/ordered.rb', line 36 def lt(value) @lt = "(#{@index.score_for_value(value)}" self end |
#lte(value) ⇒ Object
41 42 43 44 |
# File 'lib/relix/indexes/ordered.rb', line 41 def lte(value) @lt = @index.score_for_value(value) self end |
#offset(value) ⇒ Object
75 76 77 78 |
# File 'lib/relix/indexes/ordered.rb', line 75 def offset(value) @offset = value self end |
#order(value) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/relix/indexes/ordered.rb', line 61 def order(value) unless [:asc, :desc].include?(value) raise InvalidQueryOption.new("order must be :asc or :desc but was #{value.inspect}") end @order = value self end |
#zrangebyscore_limit ⇒ Object
80 81 82 83 84 85 |
# File 'lib/relix/indexes/ordered.rb', line 80 def zrangebyscore_limit # zrangebyscore uses offset/count rather than start/stop like zrange offset, stop = @index.(@redis, offset: @offset, limit: @limit) count = stop == -1 ? -1 : (stop - offset + 1) [offset, count] end |