active_orm 4.0.3 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.reek +4 -10
- data/.rubocop.yml +0 -20
- data/Gemfile +2 -0
- data/README.md +0 -1
- data/Rakefile +2 -0
- data/active_orm.gemspec +2 -1
- data/bin/console +1 -0
- data/bin/rake +2 -2
- data/lib/active_orm.rb +9 -5
- data/lib/active_orm/railtie.rb +2 -0
- data/lib/active_orm/redis/base.rb +71 -60
- data/lib/active_orm/redis/configuration.rb +32 -5
- data/lib/active_orm/redis/connection.rb +77 -73
- data/lib/active_orm/redis/geo.rb +23 -19
- data/lib/active_orm/redis/hash.rb +61 -57
- data/lib/active_orm/redis/hyper_log_log.rb +14 -10
- data/lib/active_orm/redis/key.rb +70 -66
- data/lib/active_orm/redis/list.rb +125 -121
- data/lib/active_orm/redis/pub_sub.rb +26 -22
- data/lib/active_orm/redis/script.rb +14 -10
- data/lib/active_orm/redis/set.rb +55 -51
- data/lib/active_orm/redis/sorted_set.rb +150 -146
- data/lib/active_orm/redis/string.rb +75 -71
- data/lib/active_orm/redis/transaction.rb +20 -16
- data/lib/active_orm/version.rb +3 -1
- data/lib/generators/active_orm/install_generator.rb +2 -0
- data/lib/generators/active_orm/templates/install.rb +2 -0
- data/lib/tasks/redis.rake +2 -0
- metadata +3 -20
- data/.coveralls.yml +0 -1
- data/lib/active_orm/base.rb +0 -13
- data/lib/active_orm/redis.rb +0 -23
@@ -1,31 +1,35 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
end
|
3
|
+
class ActiveOrm::Redis::PubSub < ActiveOrm::Redis::Base
|
4
|
+
class << self
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def publish(channel, message)
|
7
|
+
client.publish(channel, message)
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def subscribed?
|
11
|
+
client.subscribed?
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def subscribe(*channels, &block)
|
15
|
+
client.subscribe(channels, &block)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def unsubscribe(*channels)
|
19
|
+
client.unsubscribe(channels)
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def match_subscribe(*channels, &block)
|
23
|
+
client.psubscribe(channels, &block)
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def match_unsubscribe(*channels)
|
27
|
+
client.punsubscribe(channels)
|
28
|
+
end
|
30
29
|
|
30
|
+
def state(command, *args)
|
31
|
+
client.pubsub(command, args)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
31
35
|
end
|
@@ -1,15 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
end
|
3
|
+
class ActiveOrm::Redis::Script < ActiveOrm::Redis::Base
|
4
|
+
class << self
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def script(command, *args)
|
7
|
+
client.script(command, args)
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def eval(*args)
|
11
|
+
client.eval(:eval, args)
|
12
|
+
end
|
14
13
|
|
14
|
+
def evalsha(*args)
|
15
|
+
client.eval(:evalsha, args)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
15
19
|
end
|
data/lib/active_orm/redis/set.rb
CHANGED
@@ -1,68 +1,72 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
metatransform(value)
|
6
|
-
end
|
3
|
+
class ActiveOrm::Redis::Set < ActiveOrm::Redis::Base
|
4
|
+
class << self
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
def find(key)
|
7
|
+
value = client.smembers(normalize_key(key))
|
8
|
+
metatransform(value)
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
def combine(*args)
|
12
|
+
value = client.sunion(*args)
|
13
|
+
metatransform(value)
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
def difference(*args)
|
17
|
+
value = client.sdiff(*args)
|
18
|
+
metatransform(value)
|
19
|
+
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
def intersection(key, *args)
|
22
|
+
value = client.sinter(normalize_key(key), *args)
|
23
|
+
metatransform(value)
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
def sample(key, value = 1)
|
27
|
+
value = client.srandmember(normalize_key(key), value)
|
28
|
+
metatransform(value)
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
def value?(key, value)
|
32
|
+
client.sismember(normalize_key(key), value)
|
33
|
+
end
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def count(key)
|
36
|
+
client.scard(normalize_key(key))
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
def create(key, *args)
|
40
|
+
client.sadd(normalize_key(key), args)
|
41
|
+
end
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
def create_combination(key, *args)
|
44
|
+
client.sunionstore(normalize_key(key), args)
|
45
|
+
end
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
def create_difference(key, *args)
|
48
|
+
client.sdiffstore(normalize_key(key), *args)
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
def create_intersection(key, *args)
|
52
|
+
client.sinterstore(normalize_key(key), args)
|
53
|
+
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
def move(key, destination, value)
|
56
|
+
client.smove(normalize_key(key), destination.to_s, value)
|
57
|
+
end
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
def destroy(key, *args)
|
60
|
+
client.srem(normalize_key(key), *args)
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
def destroy_random(key)
|
64
|
+
client.spop(normalize_key(key))
|
65
|
+
end
|
67
66
|
|
67
|
+
def scan(key, cursor, opts = {})
|
68
|
+
client.sscan(normalize_key(key), cursor, opts)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
68
72
|
end
|
@@ -1,149 +1,153 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ActiveOrm::Redis::SortedSet < ActiveOrm::Redis::Base
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def find(key, position, opts = {})
|
7
|
+
position -= 1
|
8
|
+
|
9
|
+
value = client.zrange(normalize_key(key), position, position, opts)
|
10
|
+
value = value.first
|
11
|
+
value = metamorph(value) if evaluate?
|
12
|
+
value
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_score(key, position, opts = {})
|
16
|
+
value = client.zrangebyscore(normalize_key(key), position, position, opts)
|
17
|
+
value = value.first
|
18
|
+
value = metamorph(value) if evaluate?
|
19
|
+
value
|
20
|
+
end
|
21
|
+
|
22
|
+
def first(key, opts = {})
|
23
|
+
value = client.zrange(normalize_key(key), 0, 0, opts)
|
24
|
+
value = value.first
|
25
|
+
value = metamorph(value) if evaluate?
|
26
|
+
value
|
27
|
+
end
|
28
|
+
|
29
|
+
def first_score(key, opts = {})
|
30
|
+
value = client.zrangebyscore(normalize_key(key), 1, 1, opts)
|
31
|
+
value = value.first
|
32
|
+
value = metamorph(value) if evaluate?
|
33
|
+
value
|
34
|
+
end
|
35
|
+
|
36
|
+
def last(key, opts = {})
|
37
|
+
value = client.zrevrange(normalize_key(key), 0, 0, opts)
|
38
|
+
value = value.first
|
39
|
+
value = metamorph(value) if evaluate?
|
40
|
+
value
|
41
|
+
end
|
42
|
+
|
43
|
+
def last_score(key, opts = {})
|
44
|
+
value = client.zrevrangebyscore(normalize_key(key), 1, 1, opts)
|
45
|
+
value = value.first
|
46
|
+
value = metamorph(value) if evaluate?
|
47
|
+
value
|
48
|
+
end
|
49
|
+
|
50
|
+
def between(key, start, finish, opts = {})
|
51
|
+
value = client.zrange(normalize_key(key), (start - 1), (finish - 1), opts)
|
52
|
+
value = metatransform(value)
|
53
|
+
value
|
54
|
+
end
|
55
|
+
|
56
|
+
def between_reverse(key, start, finish, opts = {})
|
57
|
+
value = client.zrevrange(normalize_key(key), (start - 1), (finish - 1), opts)
|
58
|
+
value = metatransform(value)
|
59
|
+
value
|
60
|
+
end
|
61
|
+
|
62
|
+
def between_scores(key, min, max, opts = {})
|
63
|
+
value = client.zrangebyscore(normalize_key(key), min, max, opts)
|
64
|
+
value = metatransform(value)
|
65
|
+
value
|
66
|
+
end
|
67
|
+
|
68
|
+
def between_scores_reverse(key, min, max, opts = {})
|
69
|
+
value = client.zrevrangebyscore(normalize_key(key), min, max, opts)
|
70
|
+
value = metatransform(value)
|
71
|
+
value
|
72
|
+
end
|
73
|
+
|
74
|
+
def between_lex(key, min, max, opts = {})
|
75
|
+
value = client.zrangebylex(normalize_key(key), min, max, opts)
|
76
|
+
value = metatransform(value)
|
77
|
+
value
|
78
|
+
end
|
79
|
+
|
80
|
+
def between_lex_reverse(key, min, max, opts = {})
|
81
|
+
value = client.zrevrangebylex(normalize_key(key), min, max, opts)
|
82
|
+
value = metatransform(value)
|
83
|
+
value
|
84
|
+
end
|
85
|
+
|
86
|
+
def all(key, opts = {})
|
87
|
+
value = client.zrange(normalize_key(key), '-inf', '+inf', opts)
|
88
|
+
value = metatransform(value)
|
89
|
+
value
|
90
|
+
end
|
91
|
+
|
92
|
+
def position(key, value)
|
93
|
+
value = client.zrank(normalize_key(key), value)
|
94
|
+
value += 1 unless value.nil?
|
95
|
+
value
|
96
|
+
end
|
97
|
+
|
98
|
+
def position_reverse(key, value)
|
99
|
+
value = client.zrevrank(normalize_key(key), value)
|
100
|
+
value += 1 unless value.nil?
|
101
|
+
value
|
102
|
+
end
|
103
|
+
|
104
|
+
def score(key, value)
|
105
|
+
client.zscore(normalize_key(key), value)
|
106
|
+
end
|
107
|
+
|
108
|
+
def count(key)
|
109
|
+
client.zcard(normalize_key(key))
|
110
|
+
end
|
111
|
+
|
112
|
+
def count_between(key, min, max)
|
113
|
+
client.zcount(normalize_key(key), min, max)
|
114
|
+
end
|
115
|
+
|
116
|
+
def create(key, *args)
|
117
|
+
client.zadd(normalize_key(key), args)
|
118
|
+
end
|
119
|
+
|
120
|
+
def create_intersection(key, keys, opts = {})
|
121
|
+
client.zinterstore(normalize_key(key), keys, opts)
|
122
|
+
end
|
123
|
+
|
124
|
+
def create_combination(key, keys, opts = {})
|
125
|
+
client.zunionstore(normalize_key(key), keys, opts)
|
126
|
+
end
|
127
|
+
|
128
|
+
def increment(key, value, count)
|
129
|
+
client.zincrby(normalize_key(key), count, value)
|
130
|
+
end
|
131
|
+
|
132
|
+
def destroy(key, at)
|
133
|
+
client.zrem(normalize_key(key), at)
|
134
|
+
end
|
135
|
+
|
136
|
+
def destroy_between(key, start, finish)
|
137
|
+
client.zremrangebyrank(normalize_key(key), (start - 1), (finish - 1))
|
138
|
+
end
|
139
|
+
|
140
|
+
def destroy_scores(key, min, max)
|
141
|
+
client.zremrangebyscore(normalize_key(key), min, max)
|
142
|
+
end
|
143
|
+
|
144
|
+
def destroy_lex(key, min, max, opts = {})
|
145
|
+
client.zrevrangebylex(normalize_key(key), max, min, opts)
|
146
|
+
end
|
147
|
+
|
148
|
+
def scan(key, cursor, opts = {})
|
149
|
+
client.zscan(normalize_key(key), cursor, opts)
|
150
|
+
end
|
2
151
|
|
3
|
-
def self.find(key, position, opts = {})
|
4
|
-
position -= 1
|
5
|
-
|
6
|
-
value = client.zrange(normalize_key(key), position, position, opts)
|
7
|
-
value = value.first
|
8
|
-
value = metamorph(value) if evaluate?
|
9
|
-
value
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.find_score(key, position, opts = {})
|
13
|
-
value = client.zrangebyscore(normalize_key(key), position, position, opts)
|
14
|
-
value = value.first
|
15
|
-
value = metamorph(value) if evaluate?
|
16
|
-
value
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.first(key, opts = {})
|
20
|
-
value = client.zrange(normalize_key(key), 0, 0, opts)
|
21
|
-
value = value.first
|
22
|
-
value = metamorph(value) if evaluate?
|
23
|
-
value
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.first_score(key, opts = {})
|
27
|
-
value = client.zrangebyscore(normalize_key(key), 1, 1, opts)
|
28
|
-
value = value.first
|
29
|
-
value = metamorph(value) if evaluate?
|
30
|
-
value
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.last(key, opts = {})
|
34
|
-
value = client.zrevrange(normalize_key(key), 0, 0, opts)
|
35
|
-
value = value.first
|
36
|
-
value = metamorph(value) if evaluate?
|
37
|
-
value
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.last_score(key, opts = {})
|
41
|
-
value = client.zrevrangebyscore(normalize_key(key), 1, 1, opts)
|
42
|
-
value = value.first
|
43
|
-
value = metamorph(value) if evaluate?
|
44
|
-
value
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.between(key, start, finish, opts = {})
|
48
|
-
value = client.zrange(normalize_key(key), (start - 1), (finish - 1), opts)
|
49
|
-
value = metatransform(value)
|
50
|
-
value
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.between_reverse(key, start, finish, opts = {})
|
54
|
-
value = client.zrevrange(normalize_key(key), (start - 1), (finish - 1), opts)
|
55
|
-
value = metatransform(value)
|
56
|
-
value
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.between_scores(key, min, max, opts = {})
|
60
|
-
value = client.zrangebyscore(normalize_key(key), min, max, opts)
|
61
|
-
value = metatransform(value)
|
62
|
-
value
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.between_scores_reverse(key, min, max, opts = {})
|
66
|
-
value = client.zrevrangebyscore(normalize_key(key), min, max, opts)
|
67
|
-
value = metatransform(value)
|
68
|
-
value
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.between_lex(key, min, max, opts = {})
|
72
|
-
value = client.zrangebylex(normalize_key(key), min, max, opts)
|
73
|
-
value = metatransform(value)
|
74
|
-
value
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.between_lex_reverse(key, min, max, opts = {})
|
78
|
-
value = client.zrevrangebylex(normalize_key(key), min, max, opts)
|
79
|
-
value = metatransform(value)
|
80
|
-
value
|
81
|
-
end
|
82
|
-
|
83
|
-
def self.all(key, opts = {})
|
84
|
-
value = client.zrange(normalize_key(key), '-inf', '+inf', opts)
|
85
|
-
value = metatransform(value)
|
86
|
-
value
|
87
|
-
end
|
88
|
-
|
89
|
-
def self.position(key, value)
|
90
|
-
value = client.zrank(normalize_key(key), value)
|
91
|
-
value += 1 unless value.nil?
|
92
|
-
value
|
93
152
|
end
|
94
|
-
|
95
|
-
def self.position_reverse(key, value)
|
96
|
-
value = client.zrevrank(normalize_key(key), value)
|
97
|
-
value += 1 unless value.nil?
|
98
|
-
value
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.score(key, value)
|
102
|
-
client.zscore(normalize_key(key), value)
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.count(key)
|
106
|
-
client.zcard(normalize_key(key))
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.count_between(key, min, max)
|
110
|
-
client.zcount(normalize_key(key), min, max)
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.create(key, *args)
|
114
|
-
client.zadd(normalize_key(key), args)
|
115
|
-
end
|
116
|
-
|
117
|
-
def self.create_intersection(key, keys, opts = {})
|
118
|
-
client.zinterstore(normalize_key(key), keys, opts)
|
119
|
-
end
|
120
|
-
|
121
|
-
def self.create_combination(key, keys, opts = {})
|
122
|
-
client.zunionstore(normalize_key(key), keys, opts)
|
123
|
-
end
|
124
|
-
|
125
|
-
def self.increment(key, value, count)
|
126
|
-
client.zincrby(normalize_key(key), count, value)
|
127
|
-
end
|
128
|
-
|
129
|
-
def self.destroy(key, at)
|
130
|
-
client.zrem(normalize_key(key), at)
|
131
|
-
end
|
132
|
-
|
133
|
-
def self.destroy_between(key, start, finish)
|
134
|
-
client.zremrangebyrank(normalize_key(key), (start - 1), (finish - 1))
|
135
|
-
end
|
136
|
-
|
137
|
-
def self.destroy_scores(key, min, max)
|
138
|
-
client.zremrangebyscore(normalize_key(key), min, max)
|
139
|
-
end
|
140
|
-
|
141
|
-
def self.destroy_lex(key, min, max, opts = {})
|
142
|
-
client.zrevrangebylex(normalize_key(key), max, min, opts)
|
143
|
-
end
|
144
|
-
|
145
|
-
def self.scan(key, cursor, opts = {})
|
146
|
-
client.zscan(normalize_key(key), cursor, opts)
|
147
|
-
end
|
148
|
-
|
149
153
|
end
|