simple_redis 0.1.7 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0858896ace390581a00977748c3f60ab4bfdfdb
4
- data.tar.gz: de65fba9020d8c48b13daf608748daffc7e9034c
3
+ metadata.gz: 087f723bd9d7ac56465f4c284f551799bccea348
4
+ data.tar.gz: c133b2b7edad763eb3973ca05740314bdd344285
5
5
  SHA512:
6
- metadata.gz: 587f3cc5934d9c627d530943147e13c1e77a2fffa59a907c73c28fef4d47e4070262c2caaf3b4cd7b6624fe5bfd3c9a5ce776c401bb99457245c12825612037e
7
- data.tar.gz: 38d07965609c51a68cca6dd7adb5313ff8052cd8c159c9e1590650c2bf7aaefec216e53a6aeef7f64d0f2216c87fd3284eb3e931650494f98c2bc1f3b443121f
6
+ metadata.gz: fb7da3df82067becd4d644453598b4e58b88f1ee4162bfbf0e3cd23157c7fee540e054f89f86adb2c6fd12507901167cfbce16a47bbc4076fc268c181c6d4d5b
7
+ data.tar.gz: c4d55a64cd5369ce0ececc7ac3813c4c4705a06116564fa276ace7cf3f2c5bacd18f9aec7af32cff86ba3f761ff1cc85540f9eb8bf73e8b5916d17fbe99f24a6
data/README.md CHANGED
@@ -52,7 +52,7 @@ You can simply just set value to a key, with this:
52
52
  SimpleRedis.set('department-list', departments)
53
53
  ```
54
54
 
55
- ### set
55
+ ### get
56
56
  Or you can just get value of a key with this
57
57
 
58
58
  ```ruby
@@ -67,7 +67,7 @@ Create `simple_redis.rb` in `config/initializers` folder
67
67
  SimpleRedis.configuration do |config|
68
68
  config.host = "redis_host" # Default 'localhost'
69
69
  config.port = "redis_port" # Default 6379
70
- config.default_db = "redis_db_name" # Default 'simple-redis-cache'
70
+ config.default_db = "redis_db" # Default '0'
71
71
  end
72
72
  ```
73
73
 
data/lib/simple_redis.rb CHANGED
@@ -5,9 +5,11 @@ module SimpleRedis
5
5
  attr_accessor :host
6
6
  attr_accessor :port
7
7
  attr_accessor :default_db
8
+ attr_accessor :current_opts
9
+ attr_accessor :current_redis
8
10
  end
9
11
 
10
- def self.configuration(&block)
12
+ def self.configuration
11
13
  yield self
12
14
  end
13
15
 
@@ -21,7 +23,7 @@ module SimpleRedis
21
23
 
22
24
  def self.set(key, value, opts={})
23
25
  redis = get_redis(opts)
24
- result = cache redis, key, value.inspect
26
+ result = cache(redis, key, value.inspect)
25
27
  get_result(result)
26
28
  end
27
29
 
@@ -31,23 +33,36 @@ module SimpleRedis
31
33
  get_result(result)
32
34
  end
33
35
 
34
- # def self.delete_matched(key)
35
- # eval "for _,k in ipairs(redis.call('keys','session:*')) do redis.call('del',k) end" 0
36
- # redis-cli KEYS "prefix:*" | tr "\n" "\0" | xargs -0 redis-cli DEL
37
- # end
36
+ def self.total_matches(key, opts={})
37
+ redis = get_redis(opts)
38
+ redis.keys(key).size
39
+ end
40
+
41
+ def self.delete_matched(key, opts={})
42
+ redis = get_redis(opts)
43
+ redis.del(*redis.keys(key)) rescue 0
44
+ end
38
45
 
39
- private
46
+ # PRIVATE METHODS
40
47
  def self.cache(redis, key, value)
48
+ puts key
49
+ puts value
41
50
  redis.set key, value
42
51
  value
43
52
  end
44
53
 
45
- def self.get_redis(opts)
46
- Redis.new(host: host || HOST, port: port || PORT, db: opts[:db] || default_db || DEFAULT_DB)
47
- end
48
-
49
54
  def self.get_result(redis_result)
50
55
  begin eval redis_result rescue redis_result end
51
56
  end
52
57
 
58
+ def self.get_redis(opts={})
59
+ if current_opts.eql? opts
60
+ self.current_redis
61
+ else
62
+ self.current_opts = opts
63
+ self.current_redis = Redis.new(host: host || HOST, port: port || PORT, db: opts[:db] || default_db || DEFAULT_DB)
64
+ end
65
+ end
66
+ private_class_method :cache, :get_result, :get_redis
67
+
53
68
  end
@@ -1,6 +1,6 @@
1
1
  module SimpleRedis
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.0"
3
3
  HOST = "localhost"
4
4
  PORT = 6379
5
- DEFAULT_DB = "simple-redis-cache"
5
+ DEFAULT_DB = "0"
6
6
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aditia Mahdar
@@ -95,6 +95,7 @@ files:
95
95
  - test/dummy/config/locales/en.yml
96
96
  - test/dummy/config/routes.rb
97
97
  - test/dummy/config/secrets.yml
98
+ - test/dummy/dump.rdb
98
99
  - test/dummy/log/development.log
99
100
  - test/dummy/public/404.html
100
101
  - test/dummy/public/422.html
@@ -155,6 +156,7 @@ test_files:
155
156
  - test/dummy/config/routes.rb
156
157
  - test/dummy/config/secrets.yml
157
158
  - test/dummy/config.ru
159
+ - test/dummy/dump.rdb
158
160
  - test/dummy/log/development.log
159
161
  - test/dummy/public/404.html
160
162
  - test/dummy/public/422.html