hari 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/LICENSE +17 -15
- data/README.md +131 -11
- data/lib/hari/entity/property.rb +1 -2
- data/lib/hari/entity/serialization.rb +8 -8
- data/lib/hari/entity.rb +5 -0
- data/lib/hari/keys/key.rb +48 -0
- data/lib/hari/keys/list.rb +132 -0
- data/lib/hari/keys/set.rb +101 -0
- data/lib/hari/keys/sorted_set.rb +115 -0
- data/lib/hari/keys/string.rb +81 -0
- data/lib/hari/keys.rb +9 -0
- data/lib/hari/node/queries/relation/backend/sorted_set.rb +14 -4
- data/lib/hari/node/queries/relation.rb +13 -7
- data/lib/hari/node/queries/type.rb +62 -0
- data/lib/hari/node/queries.rb +10 -8
- data/lib/hari/relation/sorted_set.rb +33 -4
- data/lib/hari/relation.rb +0 -3
- data/lib/hari/version.rb +1 -1
- data/lib/hari.rb +10 -3
- data/spec/hari/keys/key_spec.rb +41 -0
- data/spec/hari/{node → keys}/lists_spec.rb +1 -1
- data/spec/hari/{node → keys}/sets_spec.rb +1 -1
- data/spec/hari/{node → keys}/sorted_sets_spec.rb +1 -1
- data/spec/hari/keys/string_spec.rb +57 -0
- data/spec/hari/node_spec.rb +45 -0
- data/spec/hari_spec.rb +13 -0
- metadata +28 -24
- data/lib/hari/node/queries/list.rb +0 -147
- data/lib/hari/node/queries/relation/backend/list.rb +0 -35
- data/lib/hari/node/queries/set.rb +0 -116
- data/lib/hari/node/queries/sorted_set.rb +0 -130
- data/lib/hari/relation/linked_list.rb +0 -16
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Rodrigues
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -140,33 +140,32 @@ dependencies:
|
|
140
140
|
name: pry
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - '>='
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: delorean
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- -
|
157
|
+
- - '>='
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- -
|
164
|
+
- - '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
-
description:
|
168
|
-
|
169
|
-
'
|
167
|
+
description: |2
|
168
|
+
Hari is a graph library on top of Redis database + Lua scripts
|
170
169
|
email: victorc.rodrigues@gmail.com
|
171
170
|
executables: []
|
172
171
|
extensions: []
|
@@ -195,21 +194,23 @@ files:
|
|
195
194
|
- lib/hari/entity/serialization/string.rb
|
196
195
|
- lib/hari/entity/serialization/time.rb
|
197
196
|
- lib/hari/errors.rb
|
197
|
+
- lib/hari/keys.rb
|
198
|
+
- lib/hari/keys/key.rb
|
199
|
+
- lib/hari/keys/list.rb
|
200
|
+
- lib/hari/keys/set.rb
|
201
|
+
- lib/hari/keys/sorted_set.rb
|
202
|
+
- lib/hari/keys/string.rb
|
198
203
|
- lib/hari/node.rb
|
199
204
|
- lib/hari/node/queries.rb
|
200
|
-
- lib/hari/node/queries/list.rb
|
201
205
|
- lib/hari/node/queries/relation.rb
|
202
|
-
- lib/hari/node/queries/relation/backend/list.rb
|
203
206
|
- lib/hari/node/queries/relation/backend/sorted_set.rb
|
204
207
|
- lib/hari/node/queries/relation/runnable.rb
|
205
208
|
- lib/hari/node/queries/relation/start.rb
|
206
209
|
- lib/hari/node/queries/relation/step.rb
|
207
|
-
- lib/hari/node/queries/
|
208
|
-
- lib/hari/node/queries/sorted_set.rb
|
210
|
+
- lib/hari/node/queries/type.rb
|
209
211
|
- lib/hari/node/repository.rb
|
210
212
|
- lib/hari/node/serialization.rb
|
211
213
|
- lib/hari/relation.rb
|
212
|
-
- lib/hari/relation/linked_list.rb
|
213
214
|
- lib/hari/relation/sorted_set.rb
|
214
215
|
- lib/hari/version.rb
|
215
216
|
- spec/hari/configuration_spec.rb
|
@@ -222,9 +223,11 @@ files:
|
|
222
223
|
- spec/hari/entity/serialization/string_spec.rb
|
223
224
|
- spec/hari/entity/serialization/time_spec.rb
|
224
225
|
- spec/hari/entity/serialization_spec.rb
|
225
|
-
- spec/hari/
|
226
|
-
- spec/hari/
|
227
|
-
- spec/hari/
|
226
|
+
- spec/hari/keys/key_spec.rb
|
227
|
+
- spec/hari/keys/lists_spec.rb
|
228
|
+
- spec/hari/keys/sets_spec.rb
|
229
|
+
- spec/hari/keys/sorted_sets_spec.rb
|
230
|
+
- spec/hari/keys/string_spec.rb
|
228
231
|
- spec/hari/node_spec.rb
|
229
232
|
- spec/hari_spec.rb
|
230
233
|
- spec/spec_helper.rb
|
@@ -238,17 +241,17 @@ require_paths:
|
|
238
241
|
- lib
|
239
242
|
required_ruby_version: !ruby/object:Gem::Requirement
|
240
243
|
requirements:
|
241
|
-
- -
|
244
|
+
- - '>='
|
242
245
|
- !ruby/object:Gem::Version
|
243
246
|
version: '0'
|
244
247
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
245
248
|
requirements:
|
246
|
-
- -
|
249
|
+
- - '>='
|
247
250
|
- !ruby/object:Gem::Version
|
248
251
|
version: '0'
|
249
252
|
requirements: []
|
250
253
|
rubyforge_project:
|
251
|
-
rubygems_version: 2.0.
|
254
|
+
rubygems_version: 2.0.3
|
252
255
|
signing_key:
|
253
256
|
specification_version: 4
|
254
257
|
summary: Hari is a graph library on top of Redis + Lua scripts
|
@@ -263,10 +266,11 @@ test_files:
|
|
263
266
|
- spec/hari/entity/serialization/string_spec.rb
|
264
267
|
- spec/hari/entity/serialization/time_spec.rb
|
265
268
|
- spec/hari/entity/serialization_spec.rb
|
266
|
-
- spec/hari/
|
267
|
-
- spec/hari/
|
268
|
-
- spec/hari/
|
269
|
+
- spec/hari/keys/key_spec.rb
|
270
|
+
- spec/hari/keys/lists_spec.rb
|
271
|
+
- spec/hari/keys/sets_spec.rb
|
272
|
+
- spec/hari/keys/sorted_sets_spec.rb
|
273
|
+
- spec/hari/keys/string_spec.rb
|
269
274
|
- spec/hari/node_spec.rb
|
270
275
|
- spec/hari_spec.rb
|
271
276
|
- spec/spec_helper.rb
|
272
|
-
has_rdoc:
|
@@ -1,147 +0,0 @@
|
|
1
|
-
module Hari
|
2
|
-
class Node < Entity
|
3
|
-
module Queries
|
4
|
-
class List
|
5
|
-
|
6
|
-
attr_reader :node, :name
|
7
|
-
|
8
|
-
def initialize(node = nil)
|
9
|
-
@node = node
|
10
|
-
end
|
11
|
-
|
12
|
-
def key
|
13
|
-
@key ||= begin
|
14
|
-
prefix = node ? "#{Hari.node_key(node)}:" : ''
|
15
|
-
prefix + name.to_s
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def list(name)
|
20
|
-
@name = name
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
def list!(name)
|
25
|
-
@name = name
|
26
|
-
range
|
27
|
-
end
|
28
|
-
|
29
|
-
def [](*args)
|
30
|
-
arg = args.first
|
31
|
-
|
32
|
-
if args.size == 2
|
33
|
-
range *args
|
34
|
-
elsif arg.kind_of? Integer
|
35
|
-
at arg
|
36
|
-
elsif arg.kind_of? Range
|
37
|
-
range arg.first, arg.last
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def first
|
42
|
-
self[0]
|
43
|
-
end
|
44
|
-
|
45
|
-
def last
|
46
|
-
self[-1]
|
47
|
-
end
|
48
|
-
|
49
|
-
def []=(index, member)
|
50
|
-
Hari.redis.lset key, index, member
|
51
|
-
end
|
52
|
-
|
53
|
-
def range(start = 0, stop = -1)
|
54
|
-
Hari.redis.lrange key, start, stop
|
55
|
-
end
|
56
|
-
|
57
|
-
alias :members :range
|
58
|
-
alias :to_a :range
|
59
|
-
|
60
|
-
def from(index)
|
61
|
-
range index
|
62
|
-
end
|
63
|
-
|
64
|
-
def to(index)
|
65
|
-
range 0, index
|
66
|
-
end
|
67
|
-
|
68
|
-
def at(index)
|
69
|
-
Hari.redis.lindex key, index
|
70
|
-
end
|
71
|
-
|
72
|
-
alias :index :at
|
73
|
-
|
74
|
-
def trim(start, stop)
|
75
|
-
Hari.redis.ltrim key, start, stop
|
76
|
-
end
|
77
|
-
|
78
|
-
def count
|
79
|
-
Hari.redis.llen key
|
80
|
-
end
|
81
|
-
|
82
|
-
alias :size :count
|
83
|
-
alias :length :count
|
84
|
-
|
85
|
-
def empty?
|
86
|
-
count == 0
|
87
|
-
end
|
88
|
-
|
89
|
-
def one?
|
90
|
-
count == 1
|
91
|
-
end
|
92
|
-
|
93
|
-
def many?
|
94
|
-
count > 1
|
95
|
-
end
|
96
|
-
|
97
|
-
def include?(member)
|
98
|
-
range.include? member
|
99
|
-
end
|
100
|
-
|
101
|
-
alias :member? :include?
|
102
|
-
|
103
|
-
def push(*members)
|
104
|
-
Hari.redis.rpush key, members
|
105
|
-
end
|
106
|
-
|
107
|
-
alias :rpush :push
|
108
|
-
alias :add :push
|
109
|
-
|
110
|
-
def lpush(*members)
|
111
|
-
Hari.redis.lpush key, members
|
112
|
-
end
|
113
|
-
|
114
|
-
def <<(member)
|
115
|
-
push member
|
116
|
-
end
|
117
|
-
|
118
|
-
def insert_before(pivot, member)
|
119
|
-
Hari.redis.linsert key, :before, pivot, member
|
120
|
-
end
|
121
|
-
|
122
|
-
def insert_after(pivot, member)
|
123
|
-
Hari.redis.linsert key, :after, pivot, member
|
124
|
-
end
|
125
|
-
|
126
|
-
alias :insert :insert_after
|
127
|
-
|
128
|
-
def delete(member, count = 0)
|
129
|
-
Hari.redis.lrem key, count, member
|
130
|
-
end
|
131
|
-
|
132
|
-
def pop
|
133
|
-
Hari.redis.rpop key
|
134
|
-
end
|
135
|
-
|
136
|
-
alias :rpop :pop
|
137
|
-
|
138
|
-
def shift
|
139
|
-
Hari.redis.lpop key
|
140
|
-
end
|
141
|
-
|
142
|
-
alias :lpop :shift
|
143
|
-
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Hari::Node::Queries::Relation
|
2
|
-
module Backend
|
3
|
-
module List
|
4
|
-
extend self
|
5
|
-
|
6
|
-
def fetch(node, options = {})
|
7
|
-
list = node.list list_name(options)
|
8
|
-
send "fetch_#{options[:result]}", list, options
|
9
|
-
end
|
10
|
-
|
11
|
-
def fetch_relations_ids(list, options = {})
|
12
|
-
start = options.fetch(:from, 0)
|
13
|
-
stop = options.limit(:limit, -1)
|
14
|
-
|
15
|
-
list.range start, stop
|
16
|
-
end
|
17
|
-
|
18
|
-
def fetch_nodes_ids(list, options)
|
19
|
-
index = list.name =~ /in$/ ? 1 : 2
|
20
|
-
fetch_relations_ids(list, options).map { |r| r.split(':')[index] }
|
21
|
-
end
|
22
|
-
|
23
|
-
def fetch_count(list, options)
|
24
|
-
list.count
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def list_name(options)
|
30
|
-
"#{options[:relation]}:#{options[:direction]}"
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
module Hari
|
2
|
-
class Node < Entity
|
3
|
-
module Queries
|
4
|
-
class Set
|
5
|
-
|
6
|
-
attr_reader :node, :name
|
7
|
-
|
8
|
-
def initialize(node = nil)
|
9
|
-
@node = node
|
10
|
-
end
|
11
|
-
|
12
|
-
def key
|
13
|
-
@key ||= begin
|
14
|
-
prefix = node ? "#{Hari.node_key(node)}:" : ''
|
15
|
-
prefix + name.to_s
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def set(name)
|
20
|
-
@name = name
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
def set!(name)
|
25
|
-
@name = name
|
26
|
-
members
|
27
|
-
end
|
28
|
-
|
29
|
-
def members
|
30
|
-
Hari.redis.smembers key
|
31
|
-
end
|
32
|
-
|
33
|
-
def rand(count = 1)
|
34
|
-
Hari.redis.srandmember key, count
|
35
|
-
end
|
36
|
-
|
37
|
-
def count
|
38
|
-
Hari.redis.scard key
|
39
|
-
end
|
40
|
-
|
41
|
-
alias :size :count
|
42
|
-
alias :length :count
|
43
|
-
|
44
|
-
def empty?
|
45
|
-
count == 0
|
46
|
-
end
|
47
|
-
|
48
|
-
def one?
|
49
|
-
count == 1
|
50
|
-
end
|
51
|
-
|
52
|
-
def many?
|
53
|
-
count > 1
|
54
|
-
end
|
55
|
-
|
56
|
-
def include?(member)
|
57
|
-
Hari.redis.sismember key, member
|
58
|
-
end
|
59
|
-
|
60
|
-
alias :member? :include?
|
61
|
-
|
62
|
-
def add(*members)
|
63
|
-
Hari.redis.sadd key, members
|
64
|
-
end
|
65
|
-
|
66
|
-
def <<(member)
|
67
|
-
add member
|
68
|
-
end
|
69
|
-
|
70
|
-
def delete(*members)
|
71
|
-
Hari.redis.srem key, members
|
72
|
-
end
|
73
|
-
|
74
|
-
def pop
|
75
|
-
Hari.redis.spop key
|
76
|
-
end
|
77
|
-
|
78
|
-
def intersect(*set_queries)
|
79
|
-
Hari.redis.sinter key, set_query_keys(set_queries)
|
80
|
-
end
|
81
|
-
|
82
|
-
def &(other_set_query)
|
83
|
-
intersect other_set_query
|
84
|
-
end
|
85
|
-
|
86
|
-
def diff(*set_queries)
|
87
|
-
Hari.redis.sdiff key, set_query_keys(set_queries)
|
88
|
-
end
|
89
|
-
|
90
|
-
def -(other_set_query)
|
91
|
-
diff other_set_query
|
92
|
-
end
|
93
|
-
|
94
|
-
private
|
95
|
-
|
96
|
-
def set_query_keys(set_queries)
|
97
|
-
keys = set_queries.map do |query|
|
98
|
-
ensure_set_query! query
|
99
|
-
query.key
|
100
|
-
end
|
101
|
-
|
102
|
-
fail 'no query keys' if keys.empty?
|
103
|
-
|
104
|
-
keys
|
105
|
-
end
|
106
|
-
|
107
|
-
def ensure_set_query!(query)
|
108
|
-
unless query.kind_of?(Hari::Node::Queries::Set)
|
109
|
-
fail 'not a set query'
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,130 +0,0 @@
|
|
1
|
-
module Hari
|
2
|
-
class Node < Entity
|
3
|
-
module Queries
|
4
|
-
class SortedSet
|
5
|
-
|
6
|
-
attr_reader :node, :name
|
7
|
-
|
8
|
-
def initialize(node = nil)
|
9
|
-
@node = node
|
10
|
-
end
|
11
|
-
|
12
|
-
def key
|
13
|
-
@key ||= begin
|
14
|
-
prefix = node ? "#{Hari.node_key(node)}:" : ''
|
15
|
-
prefix + name.to_s
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def sorted_set(name)
|
20
|
-
@name = name
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
def sorted_set!(name)
|
25
|
-
@name = name
|
26
|
-
members
|
27
|
-
end
|
28
|
-
|
29
|
-
def range(start = 0, stop = -1, options = {})
|
30
|
-
return revrange(start, stop, options) if options[:desc]
|
31
|
-
|
32
|
-
Hari.redis.zrange key, start, stop, options.slice(:with_scores)
|
33
|
-
end
|
34
|
-
|
35
|
-
alias :members :range
|
36
|
-
|
37
|
-
def range_with_scores
|
38
|
-
range 0, -1, with_scores: true
|
39
|
-
end
|
40
|
-
|
41
|
-
def revrange(start = 0, stop = -1, options = {})
|
42
|
-
Hari.redis.zrevrange key, start, stop, options.slice(:with_scores)
|
43
|
-
end
|
44
|
-
|
45
|
-
alias :reverse_range :revrange
|
46
|
-
alias :desc_range :revrange
|
47
|
-
|
48
|
-
def revrange_with_scores
|
49
|
-
revrange 0, -1, with_scores: true
|
50
|
-
end
|
51
|
-
|
52
|
-
def range_by_score(min, max, options = {})
|
53
|
-
return revrange_by_score(min, max, options) if options[:desc]
|
54
|
-
|
55
|
-
Hari.redis.zrangebyscore key, min, max, options.slice(:with_scores, :limit)
|
56
|
-
end
|
57
|
-
|
58
|
-
def revrange_by_score(min, max, options = {})
|
59
|
-
Hari.redis.zrevrangebyscore key, max, min, options.slice(:with_scores, :limit)
|
60
|
-
end
|
61
|
-
|
62
|
-
def rank(member, options = {})
|
63
|
-
return revrank(member, options) if options[:desc]
|
64
|
-
|
65
|
-
Hari.redis.zrank key, member
|
66
|
-
end
|
67
|
-
|
68
|
-
alias :ranking :rank
|
69
|
-
alias :position :rank
|
70
|
-
|
71
|
-
def revrank(member)
|
72
|
-
Hari.redis.zrevrank key, member
|
73
|
-
end
|
74
|
-
|
75
|
-
alias :reverse_ranking :revrank
|
76
|
-
alias :reverse_position :revrank
|
77
|
-
|
78
|
-
def count
|
79
|
-
Hari.redis.zcard key
|
80
|
-
end
|
81
|
-
|
82
|
-
alias :size :count
|
83
|
-
alias :length :count
|
84
|
-
|
85
|
-
def empty?
|
86
|
-
count == 0
|
87
|
-
end
|
88
|
-
|
89
|
-
def one?
|
90
|
-
count == 1
|
91
|
-
end
|
92
|
-
|
93
|
-
def many?
|
94
|
-
count > 1
|
95
|
-
end
|
96
|
-
|
97
|
-
def include?(member)
|
98
|
-
score(member).present?
|
99
|
-
end
|
100
|
-
|
101
|
-
alias :member? :include?
|
102
|
-
|
103
|
-
def score(member)
|
104
|
-
Hari.redis.zscore key, member
|
105
|
-
end
|
106
|
-
|
107
|
-
def add(*score_members)
|
108
|
-
Hari.redis.zadd key, score_members.to_a.flatten
|
109
|
-
end
|
110
|
-
|
111
|
-
def <<(*score_members)
|
112
|
-
add score_members
|
113
|
-
end
|
114
|
-
|
115
|
-
def delete(*members)
|
116
|
-
Hari.redis.zrem key, members
|
117
|
-
end
|
118
|
-
|
119
|
-
def trim_by_rank(start, stop)
|
120
|
-
Hari.redis.zremrangebyrank key, start, stop
|
121
|
-
end
|
122
|
-
|
123
|
-
def trim_by_score(min, max)
|
124
|
-
Hari.redis.zremrangebyscore key, min, max
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Hari
|
2
|
-
class Relation < Entity
|
3
|
-
module LinkedList
|
4
|
-
extend self
|
5
|
-
|
6
|
-
def create(rel)
|
7
|
-
Relation::DIRECTIONS.each { |d| Hari.redis.lpush rel.key(d), rel.id }
|
8
|
-
end
|
9
|
-
|
10
|
-
def delete(rel)
|
11
|
-
Relation::DIRECTIONS.each { |d| Hari.redis.lrem rel.key(d), 1, rel.id }
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|