queris 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +34 -0
- data/README.md +53 -0
- data/Rakefile +1 -0
- data/data/redis_scripts/add_low_ttl.lua +10 -0
- data/data/redis_scripts/copy_key_if_absent.lua +13 -0
- data/data/redis_scripts/copy_ttl.lua +13 -0
- data/data/redis_scripts/create_page_if_absent.lua +24 -0
- data/data/redis_scripts/debuq.lua +20 -0
- data/data/redis_scripts/delete_if_string.lua +8 -0
- data/data/redis_scripts/delete_matching_keys.lua +7 -0
- data/data/redis_scripts/expire_temp_query_keys.lua +7 -0
- data/data/redis_scripts/make_rangehack_if_needed.lua +30 -0
- data/data/redis_scripts/master_expire.lua +15 -0
- data/data/redis_scripts/match_key_type.lua +9 -0
- data/data/redis_scripts/move_key.lua +11 -0
- data/data/redis_scripts/multisize.lua +19 -0
- data/data/redis_scripts/paged_query_ready.lua +35 -0
- data/data/redis_scripts/periodic_zremrangebyscore.lua +9 -0
- data/data/redis_scripts/persist_reusable_temp_query_keys.lua +14 -0
- data/data/redis_scripts/query_ensure_existence.lua +23 -0
- data/data/redis_scripts/query_intersect_optimization.lua +31 -0
- data/data/redis_scripts/remove_from_keyspace.lua +27 -0
- data/data/redis_scripts/remove_from_sets.lua +13 -0
- data/data/redis_scripts/results_from_hash.lua +54 -0
- data/data/redis_scripts/results_with_ttl.lua +20 -0
- data/data/redis_scripts/subquery_intersect_optimization.lua +25 -0
- data/data/redis_scripts/subquery_intersect_optimization_cleanup.lua +5 -0
- data/data/redis_scripts/undo_add_low_ttl.lua +8 -0
- data/data/redis_scripts/unpaged_query_ready.lua +17 -0
- data/data/redis_scripts/unpersist_reusable_temp_query_keys.lua +11 -0
- data/data/redis_scripts/update_live_expiring_presence_index.lua +20 -0
- data/data/redis_scripts/update_query.lua +126 -0
- data/data/redis_scripts/update_rangehacks.lua +94 -0
- data/data/redis_scripts/zrangestore.lua +12 -0
- data/lib/queris.rb +400 -0
- data/lib/queris/errors.rb +8 -0
- data/lib/queris/indices.rb +735 -0
- data/lib/queris/mixin/active_record.rb +74 -0
- data/lib/queris/mixin/object.rb +398 -0
- data/lib/queris/mixin/ohm.rb +81 -0
- data/lib/queris/mixin/queris_model.rb +59 -0
- data/lib/queris/model.rb +455 -0
- data/lib/queris/profiler.rb +275 -0
- data/lib/queris/query.rb +1215 -0
- data/lib/queris/query/operations.rb +398 -0
- data/lib/queris/query/page.rb +101 -0
- data/lib/queris/query/timer.rb +42 -0
- data/lib/queris/query/trace.rb +108 -0
- data/lib/queris/query_store.rb +137 -0
- data/lib/queris/version.rb +3 -0
- data/lib/rails/log_subscriber.rb +22 -0
- data/lib/rails/request_timing.rb +29 -0
- data/lib/tasks/queris.rake +138 -0
- data/queris.gemspec +41 -0
- data/test.rb +39 -0
- data/test/current.rb +74 -0
- data/test/dsl.rb +35 -0
- data/test/ohm.rb +37 -0
- metadata +161 -0
data/queris.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
$:.push('lib')
|
4
|
+
require "queris/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "queris"
|
8
|
+
s.version = Queris::VERSION
|
9
|
+
s.authors = ["Leo P."]
|
10
|
+
s.email = ["queris@slact.net"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = "Redis-backed object indexing and querying module"
|
13
|
+
s.description = "We've got indices, foreign indices, ranges, subqueries, realtime queries, "
|
14
|
+
|
15
|
+
dependencies = [
|
16
|
+
# Examples:
|
17
|
+
[:runtime, "redis", "~> 3.2.1", :require => ["redis", "redis/connection/hiredis"]],
|
18
|
+
[:runtime, "hiredis"],
|
19
|
+
[:development, "pry"],
|
20
|
+
[:development, "pry-debundle"]
|
21
|
+
]
|
22
|
+
|
23
|
+
s.files = Dir['**/*']
|
24
|
+
s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
|
25
|
+
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
|
28
|
+
|
29
|
+
## Make sure you can build the gem on older versions of RubyGems too:
|
30
|
+
s.rubygems_version = "2.4.5"
|
31
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
32
|
+
s.specification_version = 3 if s.respond_to? :specification_version
|
33
|
+
|
34
|
+
dependencies.each do |type, name, version|
|
35
|
+
if s.respond_to?("add_#{type}_dependency")
|
36
|
+
s.send("add_#{type}_dependency", name, version)
|
37
|
+
else
|
38
|
+
s.add_dependency(name, version)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
class Foo
|
2
|
+
attr_accessor :wee
|
3
|
+
def initialize
|
4
|
+
@cb=[]
|
5
|
+
@wee = :foo
|
6
|
+
end
|
7
|
+
|
8
|
+
def add(cb=nil)
|
9
|
+
cb = Proc.new if cb.nil? && block_given?
|
10
|
+
raise "invalid cb" unless cb.respond_to?(:call) && cb.respond_to(:arity)
|
11
|
+
@cb << cb unless cb.nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(foo)
|
15
|
+
@cb.each do |cb|
|
16
|
+
binding.pry unless cb.respond_to? :call
|
17
|
+
cb.call(foo)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class Bar
|
24
|
+
attr_accessor :wee
|
25
|
+
def initialize
|
26
|
+
@wee = :bar
|
27
|
+
end
|
28
|
+
end
|
29
|
+
$f = Foo.new
|
30
|
+
$b = Bar.new
|
31
|
+
|
32
|
+
$f.add do |x| puts "#{x} and then some" end
|
33
|
+
beezwax = "buzz"
|
34
|
+
$f.add do |x| puts "#{x} and also #{beezwax}" end
|
35
|
+
$f.add Bar.new
|
36
|
+
$f.add $b.wee
|
37
|
+
|
38
|
+
|
39
|
+
$f.run 111
|
data/test/current.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
4
|
+
require "redis/connection/hiredis"
|
5
|
+
require "redis"
|
6
|
+
require "queris"
|
7
|
+
require "pry"
|
8
|
+
|
9
|
+
Queris.add_redis :master, Redis.new(:host => 'localhost',
|
10
|
+
:port => 6379,
|
11
|
+
:db => 13,
|
12
|
+
# :logger => Logger.new(STDOUT)
|
13
|
+
)
|
14
|
+
#Queris.add_redis :metaquery, Redis.new(:host => 'willzyx', :port => 6380)
|
15
|
+
class Bar < Queris::Model
|
16
|
+
attrs :foo_id, :bar
|
17
|
+
end
|
18
|
+
class Foo < Queris::Model
|
19
|
+
attrs :a, :b, :b2, :c
|
20
|
+
index_attribute name: :a, live: true
|
21
|
+
index_attribute :name => :here, :index => Queris::ExpiringPresenceIndex, :ttl => 120, :live => true
|
22
|
+
index_attributes :b, :b2, :index => Queris::DecayingAccumulatorIndex, :half_life => 604800
|
23
|
+
index_range_attribute :c
|
24
|
+
index_attribute_from model: Bar, name: :bar, :attribute => :bar, :key => :foo_id
|
25
|
+
#live_queries
|
26
|
+
#profile_queries :lite
|
27
|
+
end
|
28
|
+
|
29
|
+
def test
|
30
|
+
Queris.debug= true
|
31
|
+
f = Foo.new
|
32
|
+
f.a = rand
|
33
|
+
f.b = 9
|
34
|
+
f.b2 = 10
|
35
|
+
f.c = 12
|
36
|
+
binding.pry
|
37
|
+
f.save
|
38
|
+
|
39
|
+
q = Foo.query :live => true, :ttl => 60
|
40
|
+
q.union :a, 11
|
41
|
+
q.union :a, 15
|
42
|
+
q.diff :a, 12
|
43
|
+
q.union :c, 9
|
44
|
+
q.intersect :b, 12
|
45
|
+
#q.sort :c
|
46
|
+
|
47
|
+
subq = Foo.query.union(:b, 2).sort(:c)
|
48
|
+
q.union(subq)
|
49
|
+
q.sort(subq)
|
50
|
+
q.intersect Foo.query.union(:b, 44).diff(:c, 1)
|
51
|
+
q.params[:bar]=:baz
|
52
|
+
q.params[:cc]=32
|
53
|
+
|
54
|
+
d = q.marshal_dump
|
55
|
+
m = Marshal.dump q
|
56
|
+
|
57
|
+
l = Marshal.load m
|
58
|
+
#pr = Queris::QueryProfilerLite.find(q)
|
59
|
+
|
60
|
+
r = Foo.query(live: true, ttl: 30).union(:a, 1).union(:b,1).intersect(:c,3).intersect(Foo.query.union(:b2, 30).diff(:a, 10)).diff(:c, 15)
|
61
|
+
r2 = Foo.query(live: true, ttl: 120).union(:a, 1).union(:b, 22).intersect(:here).sort("-c")
|
62
|
+
hereq=Foo.query(live: true).union(:here).union(:a,1223)
|
63
|
+
binding.pry
|
64
|
+
r2.query
|
65
|
+
o = Foo.new
|
66
|
+
o.a= 1
|
67
|
+
#qqq=Queris::QueryStore.query(Foo, realtime: true).union(:a).union(:b).union(:b2)
|
68
|
+
#qqq.flush; qqq.count
|
69
|
+
#mq=Queris::QueryStore.metaquery.union(:index)
|
70
|
+
#mq.flush; mq.count
|
71
|
+
binding.pry
|
72
|
+
r.member? o
|
73
|
+
end
|
74
|
+
test
|
data/test/dsl.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
2
|
+
require "redis"
|
3
|
+
require "queris"
|
4
|
+
|
5
|
+
class Foo < Queris::Model
|
6
|
+
attrs :a, :b, :b2, :c
|
7
|
+
redis Redis.new(:host => 'localhost', :port => 6379, :db => 13, :logger => Logger.new(STDOUT))
|
8
|
+
index_attribute :a
|
9
|
+
index_attributes :b, :b2, :index => Queris::DecayingAccumulatorIndex, :half_life => 604800
|
10
|
+
index_range_attribute :c
|
11
|
+
#profile_queries :lite
|
12
|
+
end
|
13
|
+
|
14
|
+
def test
|
15
|
+
f = Foo.new
|
16
|
+
f.a = rand
|
17
|
+
f.b = 9
|
18
|
+
f.b2 = 10
|
19
|
+
f.c = 12
|
20
|
+
f.save
|
21
|
+
q = nil
|
22
|
+
1000.times do
|
23
|
+
q = Foo.query do
|
24
|
+
union :a, 11
|
25
|
+
union :a, 15
|
26
|
+
diff :a, 12
|
27
|
+
union :c, 9
|
28
|
+
intersect :b, 12
|
29
|
+
end
|
30
|
+
end
|
31
|
+
binding.pry
|
32
|
+
#pr = Queris::QueryProfilerLite.find(q)
|
33
|
+
end
|
34
|
+
|
35
|
+
test
|
data/test/ohm.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
2
|
+
require "redis/connection/hiredis"
|
3
|
+
require "redis"
|
4
|
+
require "queris"
|
5
|
+
require "ohm"
|
6
|
+
require "ohm/contrib"
|
7
|
+
|
8
|
+
Queris.add_redis :master, Redis.new(:host => 'localhost',
|
9
|
+
:port => 6379,
|
10
|
+
:db => 13,
|
11
|
+
# :logger => Logger.new(STDOUT)
|
12
|
+
)
|
13
|
+
Ohm.connect url: "redis://localhost:6379/13"
|
14
|
+
|
15
|
+
class Foo < Ohm::Model
|
16
|
+
attribute :fooo
|
17
|
+
end
|
18
|
+
|
19
|
+
class Bar < Ohm::Model
|
20
|
+
attribute :foo_id
|
21
|
+
attribute :bar
|
22
|
+
list :foolist, Foo
|
23
|
+
attribute :score
|
24
|
+
include Queris
|
25
|
+
index_attributes :foo_id, :bar, :tags, :somelist
|
26
|
+
index_range_attribute :score
|
27
|
+
end
|
28
|
+
|
29
|
+
def test
|
30
|
+
b = Bar.new
|
31
|
+
b.score=55
|
32
|
+
b.bar="a"
|
33
|
+
b.save
|
34
|
+
binding.pry
|
35
|
+
end
|
36
|
+
test
|
37
|
+
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: queris
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leo P.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hiredis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-debundle
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: 'We''ve got indices, foreign indices, ranges, subqueries, realtime queries, '
|
70
|
+
email:
|
71
|
+
- queris@slact.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- data/redis_scripts/add_low_ttl.lua
|
81
|
+
- data/redis_scripts/copy_key_if_absent.lua
|
82
|
+
- data/redis_scripts/copy_ttl.lua
|
83
|
+
- data/redis_scripts/create_page_if_absent.lua
|
84
|
+
- data/redis_scripts/debuq.lua
|
85
|
+
- data/redis_scripts/delete_if_string.lua
|
86
|
+
- data/redis_scripts/delete_matching_keys.lua
|
87
|
+
- data/redis_scripts/expire_temp_query_keys.lua
|
88
|
+
- data/redis_scripts/make_rangehack_if_needed.lua
|
89
|
+
- data/redis_scripts/master_expire.lua
|
90
|
+
- data/redis_scripts/match_key_type.lua
|
91
|
+
- data/redis_scripts/move_key.lua
|
92
|
+
- data/redis_scripts/multisize.lua
|
93
|
+
- data/redis_scripts/paged_query_ready.lua
|
94
|
+
- data/redis_scripts/periodic_zremrangebyscore.lua
|
95
|
+
- data/redis_scripts/persist_reusable_temp_query_keys.lua
|
96
|
+
- data/redis_scripts/query_ensure_existence.lua
|
97
|
+
- data/redis_scripts/query_intersect_optimization.lua
|
98
|
+
- data/redis_scripts/remove_from_keyspace.lua
|
99
|
+
- data/redis_scripts/remove_from_sets.lua
|
100
|
+
- data/redis_scripts/results_from_hash.lua
|
101
|
+
- data/redis_scripts/results_with_ttl.lua
|
102
|
+
- data/redis_scripts/subquery_intersect_optimization.lua
|
103
|
+
- data/redis_scripts/subquery_intersect_optimization_cleanup.lua
|
104
|
+
- data/redis_scripts/undo_add_low_ttl.lua
|
105
|
+
- data/redis_scripts/unpaged_query_ready.lua
|
106
|
+
- data/redis_scripts/unpersist_reusable_temp_query_keys.lua
|
107
|
+
- data/redis_scripts/update_live_expiring_presence_index.lua
|
108
|
+
- data/redis_scripts/update_query.lua
|
109
|
+
- data/redis_scripts/update_rangehacks.lua
|
110
|
+
- data/redis_scripts/zrangestore.lua
|
111
|
+
- lib/queris.rb
|
112
|
+
- lib/queris/errors.rb
|
113
|
+
- lib/queris/indices.rb
|
114
|
+
- lib/queris/mixin/active_record.rb
|
115
|
+
- lib/queris/mixin/object.rb
|
116
|
+
- lib/queris/mixin/ohm.rb
|
117
|
+
- lib/queris/mixin/queris_model.rb
|
118
|
+
- lib/queris/model.rb
|
119
|
+
- lib/queris/profiler.rb
|
120
|
+
- lib/queris/query.rb
|
121
|
+
- lib/queris/query/operations.rb
|
122
|
+
- lib/queris/query/page.rb
|
123
|
+
- lib/queris/query/timer.rb
|
124
|
+
- lib/queris/query/trace.rb
|
125
|
+
- lib/queris/query_store.rb
|
126
|
+
- lib/queris/version.rb
|
127
|
+
- lib/rails/log_subscriber.rb
|
128
|
+
- lib/rails/request_timing.rb
|
129
|
+
- lib/tasks/queris.rake
|
130
|
+
- queris.gemspec
|
131
|
+
- test.rb
|
132
|
+
- test/current.rb
|
133
|
+
- test/dsl.rb
|
134
|
+
- test/ohm.rb
|
135
|
+
homepage: ''
|
136
|
+
licenses: []
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.6.8
|
155
|
+
signing_key:
|
156
|
+
specification_version: 3
|
157
|
+
summary: Redis-backed object indexing and querying module
|
158
|
+
test_files:
|
159
|
+
- test/current.rb
|
160
|
+
- test/dsl.rb
|
161
|
+
- test/ohm.rb
|