easy_redis 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: 680f0419d720793d750bf15397c751e54bb0c1f2
4
- data.tar.gz: e53f0b8637495213e94bb973983fa0a1c7ece86b
3
+ metadata.gz: a68248d9943685f76f55cab4a361fbeac38afec1
4
+ data.tar.gz: e4b13bcfe55bb488d9dd1456d94772783ba35663
5
5
  SHA512:
6
- metadata.gz: a7d363dd6b6ab51169d96a75faa82dcfc9ed5a704a04423d41dbef76a9dcf0b333a18b2b083375718414a7624490ac9409a9702aae19816d8e4eb91bc0c97565
7
- data.tar.gz: 5b0d4fbc8c31bf991c79db0d9713d1e77ed8f55f834dce386a95b20299fc873f2716c51da4c9e21e057846c8e83932cb712d7edd6bdb5228b3429250c06934bc
6
+ metadata.gz: c4fc6e232a524341a9c8ae291f4308713d9d1adcc513c856d272120cd514054e7693362e6e29eddd96f3434e4c2819f2ea22a09d768fec5b707ee647875cdc23
7
+ data.tar.gz: e34e377338aa09c874a6212671c941faca290b05353c551bca5658743f37b775a343bb5f9ae0ec0f8062e12b27d28a6b39ccb4c22e2c4786b5efa6ec65fb74ad
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # EasyRedis
2
2
 
3
- TODO: Write a gem description
3
+ Helper methods for activerecord objects to use redis easily
4
+ Don't worry about the type casting. EasyRedis does type conversions!
4
5
 
5
6
  ## Installation
6
7
 
@@ -18,7 +19,28 @@ Or install it yourself as:
18
19
 
19
20
  ## Usage
20
21
 
21
- TODO: Write usage instructions here
22
+ Create a file under initializers directory and set a redis client like above:
23
+
24
+ EasyRedis::Redis.configure(:redis => Redis.new)
25
+
26
+ Examples:
27
+
28
+ u = User.find(1)
29
+ u.r_set("key", "value")
30
+ u.redis_set("key", "value")
31
+ u.redis_set_key("value")
32
+
33
+ u.r_get("key")
34
+ u.redis_get("key")
35
+ u.redis_get_key
36
+
37
+ u.r_del("key")
38
+ u.redis_del("key")
39
+ u.redis_del_key
40
+
41
+ u.r_update("key", "value")
42
+ u.redis_update("key", "value")
43
+ u.redis_update_key("value")
22
44
 
23
45
  ## Contributing
24
46
 
data/easy_redis.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'easy_redis/version'
4
+ require 'easy_redis/version/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "easy_redis"
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["mehmetemininac@gmail.com"]
11
11
  spec.summary = %q{Less coding for redis store}
12
12
  spec.description = %q{Creates getter and setter methods for redis store.}
13
- spec.homepage = ""
13
+ spec.homepage = "http://github.com/meinac/easy_redis"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "redis"
21
22
  spec.add_development_dependency "bundler", "~> 1.6"
22
23
  spec.add_development_dependency "rake"
23
24
  end
@@ -0,0 +1,45 @@
1
+ require "easy_redis/version/version"
2
+ require "easy_redis/initialize/active_record"
3
+
4
+ module EasyRedis
5
+
6
+ class Redis
7
+
8
+ @@redis = nil
9
+ @@config = {
10
+ namespace: "easyredis",
11
+ type_cast: true,
12
+ redis: nil
13
+ }
14
+ @@valid_config_keys = @@config.keys
15
+
16
+ class << self
17
+
18
+ def redis
19
+ @@redis
20
+ end
21
+
22
+ def redis=(redis)
23
+ @@redis = redis
24
+ end
25
+
26
+ def namespace
27
+ @@config[:namespace]
28
+ end
29
+
30
+ def use_type_casting?
31
+ @@config[:type_cast]
32
+ end
33
+
34
+ def configure(opts = {})
35
+ opts.each do |k,v|
36
+ @@config[k.to_sym] = v if @@valid_config_keys.include? k.to_sym
37
+ end
38
+ self.redis = @@config[:redis] if @@config[:redis].present?
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,7 @@
1
+ require "easy_redis/methods/methods"
2
+
3
+ class ActiveRecord::Base
4
+
5
+ include EasyRedis::Methods
6
+
7
+ end
@@ -0,0 +1,19 @@
1
+ module EasyRedis
2
+
3
+ module Deleters
4
+
5
+ def r_del(attribute)
6
+ self.redis_cli.hdel(redis_key, attribute)
7
+ end
8
+
9
+ def method_missing(meth, *args, &block)
10
+ (meth.to_s =~ /^redis_del_(.+)$/ || meth.to_s =~ /^r_del_(.+)$/) ? r_del($1) : super
11
+ end
12
+
13
+ alias_method :r_delete, :r_del
14
+ alias_method :redis_del, :r_del
15
+ alias_method :redis_delete, :r_del
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,18 @@
1
+ module EasyRedis
2
+
3
+ module Getters
4
+
5
+ def r_get(attribute)
6
+ val = self.redis_cli.hget(redis_key, attribute)
7
+ self.use_type_casting? ? YAML.load(val.to_s) : val
8
+ end
9
+
10
+ def method_missing(meth, *args, &block)
11
+ (meth.to_s =~ /^redis_get_(.+)$/ || meth.to_s =~ /^r_get_(.+)$/) ? r_get($1, *args) : super
12
+ end
13
+
14
+ alias_method :redis_get, :r_get
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,33 @@
1
+ require "easy_redis/methods/getters"
2
+ require "easy_redis/methods/setters"
3
+ require "easy_redis/methods/deleters"
4
+ require "easy_redis/methods/updaters"
5
+
6
+ module EasyRedis
7
+
8
+ module Methods
9
+
10
+ def self.included(klass)
11
+ klass.class_eval do
12
+ include EasyRedis::Getters
13
+ include EasyRedis::Setters
14
+ include EasyRedis::Deleters
15
+ include EasyRedis::Updaters
16
+ end
17
+ end
18
+
19
+ def redis_key
20
+ @redis_key ||= "#{EasyRedis::Redis.namespace}:attributes:#{self.class.name}:#{self.id}"
21
+ end
22
+
23
+ def redis_cli
24
+ EasyRedis::Redis.redis
25
+ end
26
+
27
+ def use_type_casting?
28
+ EasyRedis::Redis.use_type_casting?
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,17 @@
1
+ module EasyRedis
2
+
3
+ module Setters
4
+
5
+ def r_set(attribute, value)
6
+ self.redis_cli.hset(redis_key, attribute, YAML.dump(value))
7
+ end
8
+
9
+ def method_missing(meth, *args, &block)
10
+ (meth.to_s =~ /^redis_set_(.+)$/ || meth.to_s =~ /^r_set_(.+)$/) ? r_set($1, *args) : super
11
+ end
12
+
13
+ alias_method :redis_set, :r_set
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,20 @@
1
+ module EasyRedis
2
+
3
+ module Updaters
4
+
5
+ def r_update(attribute, value)
6
+ self.r_del(attribute)
7
+ self.r_set(attribute, value)
8
+ end
9
+
10
+ def method_missing(meth, *args, &block)
11
+ (meth.to_s =~ /^redis_update_(.+)$/ || meth.to_s =~ /^r_update_(.+)$/) ? r_delete($1, *args) : super
12
+ end
13
+
14
+ alias_method :redis_update, :r_update
15
+
16
+
17
+
18
+ end
19
+
20
+ end
@@ -1,3 +1,3 @@
1
1
  module EasyRedis
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/easy_redis.rb CHANGED
@@ -1,5 +1,4 @@
1
- require "easy_redis/version"
1
+ require "easy_redis/easy_redis"
2
2
 
3
3
  module EasyRedis
4
-
5
4
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_redis
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
  - Mehmet Emin İNAÇ
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-12 00:00:00.000000000 Z
11
+ date: 2014-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,8 +66,15 @@ files:
52
66
  - Rakefile
53
67
  - easy_redis.gemspec
54
68
  - lib/easy_redis.rb
55
- - lib/easy_redis/version.rb
56
- homepage: ''
69
+ - lib/easy_redis/easy_redis.rb
70
+ - lib/easy_redis/initialize/active_record.rb
71
+ - lib/easy_redis/methods/deleters.rb
72
+ - lib/easy_redis/methods/getters.rb
73
+ - lib/easy_redis/methods/methods.rb
74
+ - lib/easy_redis/methods/setters.rb
75
+ - lib/easy_redis/methods/updaters.rb
76
+ - lib/easy_redis/version/version.rb
77
+ homepage: http://github.com/meinac/easy_redis
57
78
  licenses:
58
79
  - MIT
59
80
  metadata: {}