counter-cache-credis 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 +4 -4
- data/README.md +54 -6
- data/lib/counter/cache/credis/counter.rb +1 -1
- data/lib/counter/cache/credis/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d461aa5d18a56b3b38020e4fa087d7ec54bb8fd
|
4
|
+
data.tar.gz: 32bad92c4022621e8ee48ba4f5839ad9cc71be0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2d180f05fd184a127c03118a06b40ca9d49946a267af0a956ea0413442d3f7a5032b5c25ba16c6892fceb0c4e5d6f2edb45aff28fb6eda97329352608ba2469
|
7
|
+
data.tar.gz: 40cfb7f6a2c5e0f7254a512ea8c4b632ca6404257b22609f1acd4b10263ca24fd414cf30743734880c8315b8d3b475cbe64875bde0b4d8e9f19ddab4dda673f4
|
data/README.md
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
# Counter::Cache::Redis
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
实现效果:
|
6
|
-
|
7
|
-
能根据不同表来设置不同字段,读取也在 redis,而不用再通过 DB
|
3
|
+
Set a counter for model through redis in order to improve perfomance.
|
8
4
|
|
9
5
|
## Installation
|
10
6
|
|
@@ -12,6 +8,7 @@ Add this line to your application's Gemfile:
|
|
12
8
|
|
13
9
|
```ruby
|
14
10
|
gem 'counter-cache-redis'
|
11
|
+
gem 'redis'
|
15
12
|
```
|
16
13
|
|
17
14
|
And then execute:
|
@@ -24,7 +21,58 @@ Or install it yourself as:
|
|
24
21
|
|
25
22
|
## Usage
|
26
23
|
|
27
|
-
|
24
|
+
### Init
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
rails g redis_config
|
28
|
+
```
|
29
|
+
It will create `config/redis.yml`
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# redis.yml
|
33
|
+
redis: &redis
|
34
|
+
redis_port: 6379
|
35
|
+
redis_namespace: 'redis'
|
36
|
+
redis_db: 0
|
37
|
+
|
38
|
+
test:
|
39
|
+
<<: *redis
|
40
|
+
redis_host: 'localhost'
|
41
|
+
|
42
|
+
development:
|
43
|
+
<<: *redis
|
44
|
+
redis_host: 'localhost'
|
45
|
+
|
46
|
+
production:
|
47
|
+
<<: *redis
|
48
|
+
redis_host: 'localhost'
|
49
|
+
|
50
|
+
```
|
51
|
+
|
52
|
+
### Use
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
student = Student.first
|
56
|
+
# It will increase itself by one
|
57
|
+
student.update_counter
|
58
|
+
# get views_count through redis
|
59
|
+
student.get_views_count_cache
|
60
|
+
```
|
61
|
+
|
62
|
+
### Configure
|
63
|
+
```ruby
|
64
|
+
class Student < ActiveRecord::Base
|
65
|
+
# select custom column
|
66
|
+
counter_cache_redis column: :hello_count
|
67
|
+
end
|
68
|
+
```
|
69
|
+
```ruby
|
70
|
+
class Student < ActiveRecord::Base
|
71
|
+
# When cache of redis is bigger than 50, it will write to db and refresh redis
|
72
|
+
# default is 20
|
73
|
+
counter_cache_redis delay: 50
|
74
|
+
end
|
75
|
+
```
|
28
76
|
|
29
77
|
## Contributing
|
30
78
|
|
@@ -18,7 +18,7 @@ module Counter
|
|
18
18
|
|
19
19
|
def counter_cache_redis(options = {})
|
20
20
|
mattr_accessor :counter_delay, :column
|
21
|
-
self.counter_delay = options[:delay] ||
|
21
|
+
self.counter_delay = options[:delay] || 20
|
22
22
|
self.column = options[:column] || 'views_count'
|
23
23
|
defind_column_getter if options[:column]
|
24
24
|
include Counter::Cache::Credis::InstanceMethods
|