counter-cache-credis 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a585b8d20156eb0c31c740f10e957f31774f0176
4
- data.tar.gz: dfec7c1f05fab6df3d672ecbbbc2110aad33f96e
3
+ metadata.gz: 3d461aa5d18a56b3b38020e4fa087d7ec54bb8fd
4
+ data.tar.gz: 32bad92c4022621e8ee48ba4f5839ad9cc71be0d
5
5
  SHA512:
6
- metadata.gz: 3cc2d71758aa92469216577aaac9c5dceec3dcbaa80fcec0947b536064c4f055bce903a760eece37c40f7c52ff66eccd118bb7643b51b5bbd10b311ce4c1e59a
7
- data.tar.gz: d1ea1e9e42a5b77628a2106206e82abcc3fd8ab1b3f9bf968408d50ae802dbc67671b4b54c944b0eb4c3f60e78ef0e32108ef9a7519da22bb7e92f0b0fa09887
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
- TODO: Write usage instructions here
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] || 1
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
@@ -1,7 +1,7 @@
1
1
  module Counter
2
2
  module Cache
3
3
  module Credis
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: counter-cache-credis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - linjunzhu