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
data/lib/active_orm/redis/geo.rb
CHANGED
@@ -1,27 +1,31 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
end
|
3
|
+
class ActiveOrm::Redis::Geo < ActiveOrm::Redis::Base
|
4
|
+
class << self
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def create
|
7
|
+
# TODO
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def hash
|
11
|
+
# TODO
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def position
|
15
|
+
# TODO
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def distance
|
19
|
+
# TODO
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def radius
|
23
|
+
# TODO
|
24
|
+
end
|
26
25
|
|
26
|
+
def radius_member
|
27
|
+
# TODO
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
27
31
|
end
|
@@ -1,75 +1,79 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
value = metamorph(value) if evaluate?
|
6
|
-
value
|
7
|
-
end
|
3
|
+
class ActiveOrm::Redis::Hash < ActiveOrm::Redis::Base
|
4
|
+
class << self
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
def find(key, field)
|
7
|
+
value = client.hget(normalize_key(key), field)
|
8
|
+
value = metamorph(value) if evaluate?
|
9
|
+
value
|
10
|
+
end
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
def find_each(key, *args)
|
13
|
+
value = client.hmget(normalize_key(key), args)
|
14
|
+
value = metamorph(value) if evaluate?
|
15
|
+
value
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
def all(key)
|
19
|
+
value = client.hgetall(normalize_key(key))
|
20
|
+
value = metamorph(value) if evaluate?
|
21
|
+
value
|
22
|
+
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
def keys(key)
|
25
|
+
value = client.hkeys(normalize_key(key))
|
26
|
+
value = metamorph(value) if evaluate?
|
27
|
+
value
|
28
|
+
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
def values(key)
|
31
|
+
value = client.hvals(normalize_key(key))
|
32
|
+
value = metamorph(value) if evaluate?
|
33
|
+
value
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def value_length(key, field)
|
37
|
+
client.hstrlen(normalize_key(key), field)
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def count(key)
|
41
|
+
client.hlen(normalize_key(key))
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
def exists?(key, field)
|
45
|
+
client.hexists(normalize_key(key), field)
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
def create(key, field, value)
|
49
|
+
client.hset(normalize_key(key), field, value)
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
def create!(key, field, value)
|
53
|
+
client.hsetnx(normalize_key(key), field, value)
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_each(key, *args)
|
57
|
+
client.hmset(normalize_key(key), args)
|
58
|
+
end
|
56
59
|
|
57
|
-
|
58
|
-
|
60
|
+
def increment(key, field, value)
|
61
|
+
normalized_key = normalize_key(key)
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
if value.is_a?(Float)
|
64
|
+
client.hincrbyfloat(normalized_key, field, value)
|
65
|
+
else
|
66
|
+
client.hincrby(normalized_key, field, value)
|
67
|
+
end
|
64
68
|
end
|
65
|
-
end
|
66
69
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
def destroy(key, *args)
|
71
|
+
client.hdel(normalize_key(key), args)
|
72
|
+
end
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
+
def scan(key, cursor, opts = {})
|
75
|
+
client.hdel(normalize_key(key), cursor, opts)
|
76
|
+
end
|
74
77
|
|
78
|
+
end
|
75
79
|
end
|
@@ -1,15 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
end
|
3
|
+
class ActiveOrm::Redis::HyperLogLog < ActiveOrm::Redis::Base
|
4
|
+
class << self
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def create(key, member)
|
7
|
+
client.pfadd(normalize_key(key), member)
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def count(*args)
|
11
|
+
client.pfcount(args)
|
12
|
+
end
|
14
13
|
|
14
|
+
def merge(key, *keys)
|
15
|
+
client.pfmerge(normalize_key(key), keys)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
15
19
|
end
|
data/lib/active_orm/redis/key.rb
CHANGED
@@ -1,91 +1,95 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
end
|
3
|
+
class ActiveOrm::Redis::Key < ActiveOrm::Redis::Base
|
4
|
+
class << self
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def exists?(key)
|
7
|
+
client.exists(normalize_key(key))
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
def type?(key)
|
11
|
+
client.type(normalize_key(key))
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
def ttl?(key, format = :seconds)
|
15
|
+
normalized_key = normalize_key(key)
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
17
|
+
seconds?(format) ? client.ttl(normalized_key) : client.pttl(normalized_key)
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def sort(key, opts = {})
|
21
|
+
client.sort(normalize_key(key), opts)
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def sample
|
25
|
+
client.randomkey
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def rename(key, value)
|
29
|
+
client.rename(normalize_key(key), value.to_s)
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def rename!(key, value)
|
33
|
+
client.renamenx(normalize_key(key), value.to_s)
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def destroy(key)
|
37
|
+
client.del(normalize_key(key))
|
38
|
+
end
|
39
|
+
|
40
|
+
def persist(key)
|
41
|
+
client.persist(normalize_key(key))
|
42
|
+
end
|
40
43
|
|
41
|
-
|
42
|
-
|
44
|
+
def expire(key, seconds, format = :seconds)
|
45
|
+
normalized_key = normalize_key(key)
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
if seconds?(format)
|
48
|
+
client.expire(normalized_key, seconds)
|
49
|
+
else
|
50
|
+
client.pexpire(normalized_key, seconds)
|
51
|
+
end
|
48
52
|
end
|
49
|
-
end
|
50
53
|
|
51
|
-
|
52
|
-
|
54
|
+
def expire_at(key, seconds, format = :seconds)
|
55
|
+
normalized_key = normalize_key(key)
|
53
56
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
57
|
+
if seconds?(format)
|
58
|
+
client.expireat(normalized_key, seconds)
|
59
|
+
else
|
60
|
+
client.pexpireat(normalized_key, seconds)
|
61
|
+
end
|
58
62
|
end
|
59
|
-
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
+
def dump(key)
|
65
|
+
client.dump(normalize_key(key))
|
66
|
+
end
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
def match(pattern = '*')
|
69
|
+
value = client.keys(normalize_key(pattern))
|
70
|
+
value = nil if value.empty?
|
71
|
+
value
|
72
|
+
end
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
+
def migrate(key, options)
|
75
|
+
client.migrate(normalize_key(key), options)
|
76
|
+
end
|
74
77
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
def move(key, destination)
|
79
|
+
client.move(normalize_key(key), destination)
|
80
|
+
end
|
78
81
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
+
def object(*args)
|
83
|
+
client.object(args)
|
84
|
+
end
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
+
def restore(key, milliseconds, value)
|
87
|
+
client.restore(normalize_key(key), milliseconds, value)
|
88
|
+
end
|
86
89
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
+
def scan(cursor, opts = {})
|
91
|
+
client.scan(cursor, opts)
|
92
|
+
end
|
90
93
|
|
94
|
+
end
|
91
95
|
end
|
@@ -1,125 +1,129 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ActiveOrm::Redis::List < ActiveOrm::Redis::Base
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def find(key, position = 1)
|
7
|
+
value = client.lindex(normalize_key(key), (position - 1))
|
8
|
+
value = metamorph(value) if evaluate?
|
9
|
+
value
|
10
|
+
end
|
11
|
+
|
12
|
+
def first(key, limit = 1)
|
13
|
+
value = client.lrange(normalize_key(key), 0, -1)
|
14
|
+
value = (limit == 1 ? value.first : value.first(limit))
|
15
|
+
value = metamorph(value) if evaluate?
|
16
|
+
value
|
17
|
+
end
|
18
|
+
|
19
|
+
def last(key, limit = 1)
|
20
|
+
value = client.lrange(normalize_key(key), 0, -1)
|
21
|
+
value = (limit == 1 ? value.last : value.last(limit))
|
22
|
+
value = metamorph(value) if evaluate?
|
23
|
+
value
|
24
|
+
end
|
25
|
+
|
26
|
+
def between(key, start = 1, finish = 0)
|
27
|
+
value = client.lrange(normalize_key(key), (start - 1), (finish - 1))
|
28
|
+
metatransform(value)
|
29
|
+
end
|
30
|
+
|
31
|
+
def all(key)
|
32
|
+
value = client.lrange(normalize_key(key), 0, -1)
|
33
|
+
metatransform(value)
|
34
|
+
end
|
35
|
+
|
36
|
+
def count(key)
|
37
|
+
client.llen(normalize_key(key))
|
38
|
+
end
|
39
|
+
|
40
|
+
def create(key, value, order = :prepend)
|
41
|
+
normalized_key = normalize_key(key)
|
42
|
+
|
43
|
+
append?(order) ? client.rpush(normalized_key, value) : client.lpush(normalized_key, value)
|
44
|
+
end
|
45
|
+
|
46
|
+
def create!(key, value, order = :prepend)
|
47
|
+
normalized_key = normalize_key(key)
|
48
|
+
|
49
|
+
append?(order) ? client.rpushx(normalized_key, value) : client.lpushx(normalized_key, value)
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_limit(key, value, limit, order = :prepend)
|
53
|
+
normalized_key = normalize_key(key)
|
54
|
+
|
55
|
+
append?(order) ? client.rpush(normalized_key, value) : client.lpush(normalized_key, value)
|
56
|
+
client.ltrim(normalized_key, 0, (limit - 1))
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_limit!(key, value, limit, order = :prepend)
|
60
|
+
normalized_key = normalize_key(key)
|
61
|
+
|
62
|
+
append?(order) ? client.rpushx(normalized_key, value) : client.lpushx(normalized_key, value)
|
63
|
+
client.ltrim(normalized_key, 0, (limit - 1))
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_before(key, pivot, value)
|
67
|
+
client.linsert(normalize_key(key), :before, pivot, value)
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_after(key, pivot, value)
|
71
|
+
client.linsert(normalize_key(key), :after, pivot, value)
|
72
|
+
end
|
73
|
+
|
74
|
+
def update(key, index, value)
|
75
|
+
client.lset(normalize_key(key), index, value)
|
76
|
+
end
|
77
|
+
|
78
|
+
def move(key, desination)
|
79
|
+
value = client.rpoplpush(normalize_key(key), normalize_key(desination))
|
80
|
+
value = metamorph(value) if evaluate?
|
81
|
+
value
|
82
|
+
end
|
83
|
+
|
84
|
+
def move_blocking(key, desination)
|
85
|
+
value = brpoplpush(normalize_key(key), normalize_key(desination))
|
86
|
+
value = metamorph(value) if evaluate?
|
87
|
+
value
|
88
|
+
end
|
89
|
+
|
90
|
+
def destroy(key, count, value)
|
91
|
+
client.lrem(normalize_key(key), count, value)
|
92
|
+
end
|
93
|
+
|
94
|
+
def destroy_first(key, limit = 1)
|
95
|
+
client.ltrim(normalize_key(key), limit, -1)
|
96
|
+
end
|
97
|
+
|
98
|
+
def destroy_last(key, limit = 1)
|
99
|
+
client.ltrim(normalize_key(key), 0, -(limit + 1))
|
100
|
+
end
|
101
|
+
|
102
|
+
def destroy_except(key, start, finish)
|
103
|
+
client.ltrim(normalize_key(key), (start - 1), (finish - 1))
|
104
|
+
end
|
105
|
+
|
106
|
+
def destroy_all(key)
|
107
|
+
client.ltrim(normalize_key(key), -1, 0)
|
108
|
+
end
|
109
|
+
|
110
|
+
def pop(key, order = :prepend)
|
111
|
+
value = append?(order) ? client.rpop(key) : client.lpop(key)
|
112
|
+
value = metamorph(value) if evaluate?
|
113
|
+
value
|
114
|
+
end
|
115
|
+
|
116
|
+
def pop_blocking(keys, opts = {})
|
117
|
+
timeout = opts[:timeout] || 0
|
118
|
+
value = if append?(opts[:order] || :prepend)
|
119
|
+
client.brpop(keys, timeout)
|
120
|
+
else
|
121
|
+
client.blpop(keys, timeout)
|
122
|
+
end
|
2
123
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
value
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.first(key, limit = 1)
|
10
|
-
value = client.lrange(normalize_key(key), 0, -1)
|
11
|
-
value = (limit == 1 ? value.first : value.first(limit))
|
12
|
-
value = metamorph(value) if evaluate?
|
13
|
-
value
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.last(key, limit = 1)
|
17
|
-
value = client.lrange(normalize_key(key), 0, -1)
|
18
|
-
value = (limit == 1 ? value.last : value.last(limit))
|
19
|
-
value = metamorph(value) if evaluate?
|
20
|
-
value
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.between(key, start = 1, finish = 0)
|
24
|
-
value = client.lrange(normalize_key(key), (start - 1), (finish - 1))
|
25
|
-
metatransform(value)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.all(key)
|
29
|
-
value = client.lrange(normalize_key(key), 0, -1)
|
30
|
-
metatransform(value)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.count(key)
|
34
|
-
client.llen(normalize_key(key))
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.create(key, value, order = :prepend)
|
38
|
-
normalized_key = normalize_key(key)
|
124
|
+
value = metamorph(value) if evaluate?
|
125
|
+
value
|
126
|
+
end
|
39
127
|
|
40
|
-
append?(order) ? client.rpush(normalized_key, value) : client.lpush(normalized_key, value)
|
41
128
|
end
|
42
|
-
|
43
|
-
def self.create!(key, value, order = :prepend)
|
44
|
-
normalized_key = normalize_key(key)
|
45
|
-
|
46
|
-
append?(order) ? client.rpushx(normalized_key, value) : client.lpushx(normalized_key, value)
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.create_limit(key, value, limit, order = :prepend)
|
50
|
-
normalized_key = normalize_key(key)
|
51
|
-
|
52
|
-
append?(order) ? client.rpush(normalized_key, value) : client.lpush(normalized_key, value)
|
53
|
-
client.ltrim(normalized_key, 0, (limit - 1))
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.create_limit!(key, value, limit, order = :prepend)
|
57
|
-
normalized_key = normalize_key(key)
|
58
|
-
|
59
|
-
append?(order) ? client.rpushx(normalized_key, value) : client.lpushx(normalized_key, value)
|
60
|
-
client.ltrim(normalized_key, 0, (limit - 1))
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.create_before(key, pivot, value)
|
64
|
-
client.linsert(normalize_key(key), :before, pivot, value)
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.create_after(key, pivot, value)
|
68
|
-
client.linsert(normalize_key(key), :after, pivot, value)
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.update(key, index, value)
|
72
|
-
client.lset(normalize_key(key), index, value)
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.move(key, desination)
|
76
|
-
value = client.rpoplpush(normalize_key(key), normalize_key(desination))
|
77
|
-
value = metamorph(value) if evaluate?
|
78
|
-
value
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.move_blocking(key, desination)
|
82
|
-
value = brpoplpush(normalize_key(key), normalize_key(desination))
|
83
|
-
value = metamorph(value) if evaluate?
|
84
|
-
value
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.destroy(key, count, value)
|
88
|
-
client.lrem(normalize_key(key), count, value)
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.destroy_first(key, limit = 1)
|
92
|
-
client.ltrim(normalize_key(key), limit, -1)
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.destroy_last(key, limit = 1)
|
96
|
-
client.ltrim(normalize_key(key), 0, -(limit + 1))
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.destroy_except(key, start, finish)
|
100
|
-
client.ltrim(normalize_key(key), (start - 1), (finish - 1))
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.destroy_all(key)
|
104
|
-
client.ltrim(normalize_key(key), -1, 0)
|
105
|
-
end
|
106
|
-
|
107
|
-
def self.pop(key, order = :prepend)
|
108
|
-
value = append?(order) ? client.rpop(key) : client.lpop(key)
|
109
|
-
value = metamorph(value) if evaluate?
|
110
|
-
value
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.pop_blocking(keys, opts = {})
|
114
|
-
timeout = opts[:timeout] || 0
|
115
|
-
value = if append?(opts[:order] || :prepend)
|
116
|
-
client.brpop(keys, timeout)
|
117
|
-
else
|
118
|
-
client.blpop(keys, timeout)
|
119
|
-
end
|
120
|
-
|
121
|
-
value = metamorph(value) if evaluate?
|
122
|
-
value
|
123
|
-
end
|
124
|
-
|
125
129
|
end
|