active_redis 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +31 -6
- data/lib/active_redis/connection_ext/finders_layer.rb +4 -0
- data/lib/active_redis/finders.rb +3 -1
- data/lib/active_redis/helpers/lua_scripts.rb +7 -0
- data/lib/active_redis/lua_scripts/main.lua +22 -0
- data/lib/active_redis/persistence.rb +1 -1
- data/lib/active_redis/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjMwYzRjYzgwNGQzN2U4MTk4MDc0NGVhNzE5YmUzOWEyNjZjNmQ0Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmYwMzc0ZGI0YmZjMzczMTU2MTI0MzE2YzMyMjU0YTU3NDg2ZGQyNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzM1ZDAzMzZmMTE2ZjIxNTYxYzIzNTdhZjhkYzA0ZWM5OTljYmY2ZjM4NzEw
|
10
|
+
ZTEwYjZkMDg0NDJhYmNkODNiNmU5NjM1MDQ5N2FmZDk2NDQzODBmNjRhYTY1
|
11
|
+
NGI0MzA3YjM3MWQ2YTUwMWM0ZGZhOTgyZDQ1NGFjMjFkYmRiMDY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjNmMTdiYWY1M2E3OWFiOWRlMTRlYzg3MmM5Mzg2MDQwYjg5YmQyMjM1Mjll
|
14
|
+
NzUzYjI4ZmU1OWIyMmZkYTgyZTY1NTUyZmI3OWY4ZjRhNjQ2YTBiZjFiYTM5
|
15
|
+
ZjliYWE0ODM0MDkxMTVmOWI0NWI1YjMzMTc4NjMxMWI2ZjkzOGY=
|
data/README.md
CHANGED
@@ -67,26 +67,51 @@ article.update(title: "New article title") # => true
|
|
67
67
|
p article.title # => New article title
|
68
68
|
|
69
69
|
another_article.destroy
|
70
|
+
|
71
|
+
Article.destroy_all
|
72
|
+
|
73
|
+
p Article.count # => 0
|
70
74
|
```
|
71
75
|
|
72
76
|
### Finders and Calculations
|
73
77
|
|
74
|
-
|
78
|
+
You may find 'row' by it's id
|
75
79
|
|
76
80
|
```ruby
|
77
81
|
Article.find(1) # => [#<Article:0x007fec2526f4f8 @updated_at="1382608780", @link="http://someblog.com/1", @id="1", @title="Some title", @created_at="1382608780">]
|
78
82
|
```
|
79
83
|
|
80
|
-
|
84
|
+
Also gem add support for some aggregation functions like __sum__, __min__, __max__, __pluck__
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
class Article < ActiveRedis::Base
|
88
|
+
attributes :link, :title, :views
|
89
|
+
end
|
90
|
+
|
91
|
+
Article.create(views: 1000, link: "http://someblog.com/1", title: "Title article")
|
92
|
+
Article.create(views: 3000, link: "http://someblog.com/2", title: "Title article")
|
93
|
+
|
94
|
+
Article.sum(:views) # => 4000
|
95
|
+
Article.min(:views) # => 1000
|
96
|
+
Article.max(:views) # => 3000
|
97
|
+
Article.pluck(:id) # => ["1", "2"]
|
98
|
+
```
|
99
|
+
|
100
|
+
From version 0.0.2 you are able to search item by multiple attributes using method __where__
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
Article.where(title: "Title article", views: 1000)
|
104
|
+
```
|
81
105
|
|
82
106
|
### Future work
|
83
107
|
|
84
108
|
At an early time I want to implement such features:
|
85
109
|
|
86
|
-
1. Add
|
87
|
-
2.
|
88
|
-
3.
|
89
|
-
4.
|
110
|
+
1. Add _all_ class method
|
111
|
+
2. Implement Association module
|
112
|
+
3. Setting/getting attributes with it's types
|
113
|
+
4. Relational Operators in where
|
114
|
+
5. Scopes???
|
90
115
|
|
91
116
|
## Contributing
|
92
117
|
|
data/lib/active_redis/finders.rb
CHANGED
@@ -5,7 +5,9 @@ module ActiveRedis
|
|
5
5
|
ids.map { |id| self.new(ActiveRedis.connection.fetch_row(self, id)) }
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
def where(params)
|
9
|
+
ActiveRedis.connection.fetch_where(self, params).map { |attrs| self.new(attrs) }
|
10
|
+
end
|
9
11
|
|
10
12
|
end
|
11
13
|
end
|
@@ -47,4 +47,26 @@ local calculate_sum = function (key, attr)
|
|
47
47
|
sum = sum + s
|
48
48
|
end
|
49
49
|
return sum
|
50
|
+
end
|
51
|
+
|
52
|
+
local is_match_record = function (key, argv)
|
53
|
+
for i = 1, #argv, 2 do
|
54
|
+
local k = argv[i]
|
55
|
+
local value = argv[i+1]
|
56
|
+
if (redis.call("HGET", key, k) ~= value) then
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
return true
|
61
|
+
end
|
62
|
+
|
63
|
+
local where_finder = function (key, argv)
|
64
|
+
local result = {}
|
65
|
+
local ks = keys(key)
|
66
|
+
for index, k in pairs(ks) do
|
67
|
+
if is_match_record(k, argv) == true then
|
68
|
+
table.insert(result, redis.call("HGETALL", k))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
return result
|
50
72
|
end
|
data/lib/active_redis/version.rb
CHANGED