redcord 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redcord/actions.rb +14 -9
- data/lib/redcord/attribute.rb +1 -4
- data/lib/redcord/connection_pool.rb +4 -4
- data/lib/redcord/errors.rb +20 -0
- data/lib/redcord/migration/index.rb +1 -1
- data/lib/redcord/relation.rb +3 -7
- data/lib/redcord/serializer.rb +1 -9
- data/lib/redcord.rb +1 -0
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c343794236cfb0990142a2200625066bd176b3f57cdfbf4336e752a568796621
|
4
|
+
data.tar.gz: d4dff503e7bf52756ea884be7179a2b7a0b004ab5c93d8af24a8fa7bee953e76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78d24a7abea242512ad8943c19b50ad363ee320204c3e56d386f6b408e4d11c508dd35f724490963546817f87c53a2b38cb496035bd1b1a4e0c078b78503c1ff
|
7
|
+
data.tar.gz: a3660d9cb64af06ae210e1885be8de10e9285edea5671252204caea07eda43c0b7fc899a29f5d5975c1cc2c216abd61345b6211a9e83dffdc3920e45704d42d0
|
data/lib/redcord/actions.rb
CHANGED
@@ -3,15 +3,8 @@
|
|
3
3
|
# typed: strict
|
4
4
|
|
5
5
|
require 'sorbet-coerce'
|
6
|
-
|
7
6
|
require 'redcord/relation'
|
8
7
|
|
9
|
-
module Redcord
|
10
|
-
# Raised by Model.find
|
11
|
-
class RecordNotFound < StandardError; end
|
12
|
-
class InvalidAction < StandardError; end
|
13
|
-
end
|
14
|
-
|
15
8
|
module Redcord::Actions
|
16
9
|
extend T::Sig
|
17
10
|
extend T::Helpers
|
@@ -171,6 +164,13 @@ module Redcord::Actions
|
|
171
164
|
)
|
172
165
|
end
|
173
166
|
end
|
167
|
+
# TODO: break down Redis::CommandError further by parsing the error message
|
168
|
+
rescue Redis::CommandError => e
|
169
|
+
if e.message.include?('has been deleted')
|
170
|
+
raise Redcord::RedcordDeletedError.new(e)
|
171
|
+
else
|
172
|
+
raise e
|
173
|
+
end
|
174
174
|
end
|
175
175
|
|
176
176
|
sig { returns(T::Boolean) }
|
@@ -179,7 +179,6 @@ module Redcord::Actions
|
|
179
179
|
|
180
180
|
true
|
181
181
|
rescue Redis::CommandError
|
182
|
-
# TODO: break down Redis::CommandError by parsing the error message
|
183
182
|
false
|
184
183
|
end
|
185
184
|
|
@@ -213,6 +212,13 @@ module Redcord::Actions
|
|
213
212
|
)
|
214
213
|
end
|
215
214
|
end
|
215
|
+
# TODO: break down Redis::CommandError further by parsing the error message
|
216
|
+
rescue Redis::CommandError => e
|
217
|
+
if e.message.include?('has been deleted')
|
218
|
+
raise Redcord::RedcordDeletedError.new(e)
|
219
|
+
else
|
220
|
+
raise e
|
221
|
+
end
|
216
222
|
end
|
217
223
|
|
218
224
|
sig { params(args: T::Hash[Symbol, T.untyped]).returns(T::Boolean) }
|
@@ -221,7 +227,6 @@ module Redcord::Actions
|
|
221
227
|
|
222
228
|
true
|
223
229
|
rescue Redis::CommandError
|
224
|
-
# TODO: break down Redis::CommandError by parsing the error message
|
225
230
|
false
|
226
231
|
end
|
227
232
|
|
data/lib/redcord/attribute.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# typed: strict
|
4
|
-
module Redcord
|
5
|
-
class InvalidAttribute < StandardError; end
|
6
|
-
end
|
7
4
|
|
8
5
|
module Redcord::Attribute
|
9
6
|
extend T::Sig
|
@@ -37,7 +34,7 @@ module Redcord::Attribute
|
|
37
34
|
klass.include(InstanceMethods)
|
38
35
|
klass.class_variable_set(:@@index_attributes, Set.new)
|
39
36
|
klass.class_variable_set(:@@range_index_attributes, Set.new)
|
40
|
-
klass.class_variable_set(:@@custom_index_attributes, Hash.new
|
37
|
+
klass.class_variable_set(:@@custom_index_attributes, Hash.new)
|
41
38
|
klass.class_variable_set(:@@ttl, nil)
|
42
39
|
klass.class_variable_set(:@@shard_by_attribute, nil)
|
43
40
|
end
|
@@ -13,16 +13,16 @@ class Redcord::ConnectionPool
|
|
13
13
|
# Avoid method_missing when possible for better performance
|
14
14
|
methods = Set.new(Redcord::Redis.instance_methods(false) + Redis.instance_methods(false))
|
15
15
|
methods.each do |method_name|
|
16
|
-
define_method method_name do |*args, &blk|
|
16
|
+
define_method method_name do |*args, **kwargs, &blk|
|
17
17
|
@connection_pool.with do |redis|
|
18
|
-
redis.send(method_name, *args, &blk)
|
18
|
+
redis.send(method_name, *args, **kwargs, &blk)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def method_missing(method_name, *args, &blk)
|
23
|
+
def method_missing(method_name, *args, **kwargs, &blk)
|
24
24
|
@connection_pool.with do |redis|
|
25
|
-
redis.send(method_name, *args, &blk)
|
25
|
+
redis.send(method_name, *args, **kwargs, &blk)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Redcord
|
4
|
+
class RedcordError < StandardError; end
|
5
|
+
|
6
|
+
# Raised by Model.find
|
7
|
+
class RecordNotFound < RedcordError; end
|
8
|
+
class InvalidAction < RedcordError; end
|
9
|
+
|
10
|
+
# Raised by Model.where
|
11
|
+
class InvalidQuery < RedcordError; end
|
12
|
+
class AttributeNotIndexed < RedcordError; end
|
13
|
+
class WrongAttributeType < TypeError; end
|
14
|
+
class CustomIndexInvalidQuery < RedcordError; end
|
15
|
+
class CustomIndexInvalidDesign < RedcordError; end
|
16
|
+
class RedcordDeletedError < ::Redis::CommandError; end
|
17
|
+
|
18
|
+
# Raised by shared_by_attribute
|
19
|
+
class InvalidAttribute < RedcordError; end
|
20
|
+
end
|
@@ -48,7 +48,7 @@ module Redcord::Migration::Index
|
|
48
48
|
sig { params(model: T.class_of(Redcord::Base), key: String).void }
|
49
49
|
def _del_zset(model, key)
|
50
50
|
# ZPOPMIN might not be avaliable on old redis servers
|
51
|
-
model.redis.zscan_each(
|
51
|
+
model.redis.zscan_each(key) do |id, _|
|
52
52
|
model.redis.zrem(key, id)
|
53
53
|
end
|
54
54
|
|
data/lib/redcord/relation.rb
CHANGED
@@ -6,10 +6,6 @@ require 'active_support'
|
|
6
6
|
require 'active_support/core_ext/array'
|
7
7
|
require 'active_support/core_ext/module'
|
8
8
|
|
9
|
-
module Redcord
|
10
|
-
class InvalidQuery < StandardError; end
|
11
|
-
end
|
12
|
-
|
13
9
|
class Redcord::Relation
|
14
10
|
extend T::Sig
|
15
11
|
|
@@ -99,7 +95,7 @@ class Redcord::Relation
|
|
99
95
|
extract_query_conditions!,
|
100
96
|
index_attrs: model._script_arg_index_attrs,
|
101
97
|
range_index_attrs: model._script_arg_range_index_attrs,
|
102
|
-
custom_index_attrs: model._script_arg_custom_index_attrs[custom_index_name],
|
98
|
+
custom_index_attrs: model._script_arg_custom_index_attrs[custom_index_name] || [],
|
103
99
|
hash_tag: extract_hash_tag!,
|
104
100
|
custom_index_name: custom_index_name
|
105
101
|
)
|
@@ -223,7 +219,7 @@ class Redcord::Relation
|
|
223
219
|
select_attrs: select_attrs,
|
224
220
|
index_attrs: model._script_arg_index_attrs,
|
225
221
|
range_index_attrs: model._script_arg_range_index_attrs,
|
226
|
-
custom_index_attrs: model._script_arg_custom_index_attrs[custom_index_name],
|
222
|
+
custom_index_attrs: model._script_arg_custom_index_attrs[custom_index_name] || [],
|
227
223
|
hash_tag: extract_hash_tag!,
|
228
224
|
custom_index_name: custom_index_name
|
229
225
|
)
|
@@ -239,7 +235,7 @@ class Redcord::Relation
|
|
239
235
|
extract_query_conditions!,
|
240
236
|
index_attrs: model._script_arg_index_attrs,
|
241
237
|
range_index_attrs: model._script_arg_range_index_attrs,
|
242
|
-
custom_index_attrs: model._script_arg_custom_index_attrs[custom_index_name],
|
238
|
+
custom_index_attrs: model._script_arg_custom_index_attrs[custom_index_name] || [],
|
243
239
|
hash_tag: extract_hash_tag!,
|
244
240
|
custom_index_name: custom_index_name
|
245
241
|
)
|
data/lib/redcord/serializer.rb
CHANGED
@@ -4,14 +4,6 @@
|
|
4
4
|
|
5
5
|
require 'redcord/range_interval'
|
6
6
|
|
7
|
-
module Redcord
|
8
|
-
# Raised by Model.where
|
9
|
-
class AttributeNotIndexed < StandardError; end
|
10
|
-
class WrongAttributeType < TypeError; end
|
11
|
-
class CustomIndexInvalidQuery < StandardError; end
|
12
|
-
class CustomIndexInvalidDesign < StandardError; end
|
13
|
-
end
|
14
|
-
|
15
7
|
# This module defines various helper methods on Redcord for serialization
|
16
8
|
# between the Ruby client and Redis server.
|
17
9
|
module Redcord::Serializer
|
@@ -81,7 +73,7 @@ module Redcord::Serializer
|
|
81
73
|
attr_keys.each do |attr_key|
|
82
74
|
next if attr_key == shard_by_attribute
|
83
75
|
|
84
|
-
if !custom_index_attributes.empty?
|
76
|
+
if !custom_index_attributes.nil? && !custom_index_attributes.empty?
|
85
77
|
if !custom_index_attributes.include?(attr_key)
|
86
78
|
raise(
|
87
79
|
Redcord::AttributeNotIndexed,
|
data/lib/redcord.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redcord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chan Zuckerberg Initiative
|
@@ -123,35 +123,35 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 0.4.4704
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: rspec
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '3.2'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '3.2'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: simplecov
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
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
|
-
version: '
|
152
|
+
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name: simplecov
|
154
|
+
name: simplecov-cobertura
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- lib/redcord/base.rb
|
178
178
|
- lib/redcord/configurations.rb
|
179
179
|
- lib/redcord/connection_pool.rb
|
180
|
+
- lib/redcord/errors.rb
|
180
181
|
- lib/redcord/logger.rb
|
181
182
|
- lib/redcord/lua_script_reader.rb
|
182
183
|
- lib/redcord/migration.rb
|
@@ -213,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
213
214
|
requirements:
|
214
215
|
- - ">="
|
215
216
|
- !ruby/object:Gem::Version
|
216
|
-
version: 2.
|
217
|
+
version: 2.7.0
|
217
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
219
|
requirements:
|
219
220
|
- - ">="
|