redpear 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/redpear.rb CHANGED
@@ -4,9 +4,8 @@ require "set"
4
4
  require "securerandom"
5
5
 
6
6
  module Redpear
7
- autoload :Concern, "redpear/concern"
8
- autoload :Connection, "redpear/connection"
9
- autoload :Model, "redpear/model"
10
- autoload :Schema, "redpear/schema"
11
- autoload :Store, "redpear/store"
12
7
  end
8
+
9
+ %w|concern store|.each do |name|
10
+ require "redpear/#{name}"
11
+ end
data/lib/redpear/model.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'redpear'
2
+ require 'redpear/schema'
2
3
 
3
4
  =begin
4
5
  Redis is a simple key/value store, hence storing structured data can be a
@@ -21,8 +22,8 @@ Redpear::Model is VERY lightweight. It is optimised for raw speed at the
21
22
  expense of convenience.
22
23
  =end
23
24
  class Redpear::Model < Hash
24
- autoload :Finders, 'redpear/model/finders'
25
- autoload :Expiration, 'redpear/model/expiration'
25
+ require 'redpear/model/finders'
26
+ require 'redpear/model/expiration'
26
27
 
27
28
  include Redpear::Schema
28
29
  include Finders
@@ -1,8 +1,4 @@
1
1
  module Redpear::Schema
2
- autoload :Collection, 'redpear/schema/collection'
3
- autoload :Column, 'redpear/schema/column'
4
- autoload :Index, 'redpear/schema/index'
5
- autoload :Score, 'redpear/schema/score'
6
2
  extend Redpear::Concern
7
3
 
8
4
  module ClassMethods
@@ -42,3 +38,7 @@ module Redpear::Schema
42
38
 
43
39
  end
44
40
  end
41
+
42
+ %w|collection column index score|.each do |name|
43
+ require "redpear/schema/#{name}"
44
+ end
data/lib/redpear/store.rb CHANGED
@@ -1,11 +1,6 @@
1
1
  module Redpear::Store
2
- autoload :Base, 'redpear/store/base'
3
- autoload :Counter, 'redpear/store/counter'
4
- autoload :Enumerable, 'redpear/store/enumerable'
5
- autoload :Hash, 'redpear/store/hash'
6
- autoload :List, 'redpear/store/list'
7
- autoload :Lock, 'redpear/store/lock'
8
- autoload :Set, 'redpear/store/set'
9
- autoload :SortedSet, 'redpear/store/sorted_set'
10
- autoload :Value, 'redpear/store/value'
11
- end
2
+ end
3
+
4
+ %w|base value counter enumerable hash list lock set sorted_set|.each do |name|
5
+ require "redpear/store/#{name}"
6
+ end
@@ -60,7 +60,8 @@ class Redpear::Store::Base
60
60
  # Watch this key
61
61
  # @return [Boolean] true if successful
62
62
  def watch(&block)
63
- conn.watch(key, &block).nil?
63
+ conn.watch(key, &block)
64
+ true
64
65
  end
65
66
 
66
67
  # @return [Integer] remaining time-to-live in seconds (if set)
@@ -1,8 +1,8 @@
1
1
  module Redpear
2
2
  module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 9
5
- TINY = 1
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ TINY = 0
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redpear
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-13 00:00:00.000000000 Z
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -130,29 +130,28 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - lib/redpear.rb
133
- - lib/redpear/connection.rb
134
- - lib/redpear/schema/column.rb
135
- - lib/redpear/schema/index.rb
136
- - lib/redpear/schema/collection.rb
137
- - lib/redpear/schema/score.rb
133
+ - lib/redpear/schema.rb
138
134
  - lib/redpear/concern.rb
135
+ - lib/redpear/model.rb
136
+ - lib/redpear/version.rb
139
137
  - lib/redpear/store.rb
138
+ - lib/redpear/model/machinist.rb
140
139
  - lib/redpear/model/factory_girl.rb
141
140
  - lib/redpear/model/finders.rb
142
141
  - lib/redpear/model/expiration.rb
143
- - lib/redpear/model/machinist.rb
144
- - lib/redpear/version.rb
142
+ - lib/redpear/store/list.rb
143
+ - lib/redpear/store/set.rb
144
+ - lib/redpear/store/sorted_set.rb
145
145
  - lib/redpear/store/lock.rb
146
+ - lib/redpear/store/value.rb
146
147
  - lib/redpear/store/enumerable.rb
147
- - lib/redpear/store/counter.rb
148
148
  - lib/redpear/store/hash.rb
149
149
  - lib/redpear/store/base.rb
150
- - lib/redpear/store/value.rb
151
- - lib/redpear/store/list.rb
152
- - lib/redpear/store/set.rb
153
- - lib/redpear/store/sorted_set.rb
154
- - lib/redpear/model.rb
155
- - lib/redpear/schema.rb
150
+ - lib/redpear/store/counter.rb
151
+ - lib/redpear/schema/collection.rb
152
+ - lib/redpear/schema/column.rb
153
+ - lib/redpear/schema/index.rb
154
+ - lib/redpear/schema/score.rb
156
155
  homepage: https://github.com/bsm/redpear
157
156
  licenses: []
158
157
  post_install_message:
@@ -173,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
172
  version: 1.3.6
174
173
  requirements: []
175
174
  rubyforge_project:
176
- rubygems_version: 1.8.24
175
+ rubygems_version: 1.8.25
177
176
  signing_key:
178
177
  specification_version: 3
179
178
  summary: Redpear, a Redis ORM
@@ -1,99 +0,0 @@
1
- # == Redpear::Connection
2
- #
3
- # Abstract connection class, with support for master/slave sharding.
4
- # @see Redpear::Connection#initialize for examples
5
- #
6
- class Redpear::Connection
7
-
8
- MASTER_METHODS = [
9
- :append, :blpop, :brpop, :brpoplpush, :decr, :decrby, :del, :discard,
10
- :eval, :evalsha, :exec, :expire, :expireat, :getset,
11
- :hset, :hsetnx, :hincrby, :hmset, :hdel, :hincrbyfloat,
12
- :incr, :incrby, :incrbyfloat,
13
- :linsert, :lpop, :lpush, :lpushx, :lrem, :lset, :ltrim,
14
- :mapped_hmset, :mapped_mset, :mapped_msetnx, :move, :mset, :msetnx,
15
- :multi, :persist, :pipelined, :rename, :renamenx, :rpop, :rpoplpush,
16
- :pexpire, :pexpireat, :psetex, :pttl, :rpush, :rpushx,
17
- :sadd, :script, :sdiffstore, :set, :setbit, :setex, :setnx,
18
- :setrange, :sinterstore, :smove, :spop, :srem, :sunionstore, :unwatch,
19
- :watch, :zadd, :zincrby, :zinterstore, :zrem, :zremrangebyrank,
20
- :zremrangebyscore, :zunionstore, :[]=
21
- ].freeze
22
-
23
- SLAVE_METHODS = [
24
- :auth, :bgrewriteaof, :bgsave, :config, :dbsize, :debug, :get, :getbit,
25
- :getrange, :echo, :exists, :flushall, :flushdb, :hget, :hmget, :hexists,
26
- :hlen, :hkeys, :hvals, :hgetall, :info, :keys, :lastsave, :lindex, :llen,
27
- :lrange, :mapped_hmget, :mapped_mget, :mget, :monitor, :object, :ping,
28
- :publish, :psubscribe, :punsubscribe, :quit, :randomkey, :save, :scard,
29
- :sdiff, :select, :shutdown, :sinter, :sismember, :slaveof, :slowlog, :smembers,
30
- :sort, :srandmember, :strlen, :subscribe, :subscribed?, :sunion, :sync, :synchronize,
31
- :time, :ttl, :type, :unsubscribe, :zcard, :zcount, :zrange,
32
- :zrangebyscore, :zrank, :zrevrange, :zrevrangebyscore, :zrevrank, :zscore,
33
- :[]
34
- ].freeze
35
-
36
- # @return [Symbol] ther current connection, either :master or :slave
37
- attr_reader :current
38
- attr_accessor :master, :slave
39
-
40
- # Constructor, accepts a master connection and an optional slave connection.
41
- # Connections can be instances of Redis::Client, URL strings, or e.g.
42
- # ConnectionPool objects. Examples:
43
- #
44
- # # Use current redis client as master and slave
45
- # Redpear::Connection.new Redis.current
46
- #
47
- # # Use current redis client as slave and a remote URL as master
48
- # Redpear::Connection.new "redis://master.host:6379", Redis.current
49
- #
50
- # # Use a connection pool - https://github.com/mperham/connection_pool
51
- # slave_pool = ConnectionPool.new(:size => 5, :timeout => 5) { Redis.connect("redis://slave.host:6379") }
52
- # Redpear::Connection.new "redis://master.host:6379", slave_pool
53
- #
54
- # @param [Redis::Client|String|ConnectionPool] master
55
- # The master connection, defaults to `Redis.current`
56
- # @param [Redis::Client|String|ConnectionPool] slave
57
- # The (optional) slave connection, defaults to master
58
- def initialize(master = Redis.current, slave = nil)
59
- @master = _connect(master)
60
- @slave = slave ? _connect(slave) : @master
61
- end
62
-
63
- # @param [Symbol] name
64
- # Either :master or :slave
65
- # @yield
66
- # Perform a block with the given connection
67
- # @yieldparam [Redpear::Connection]
68
- # The chosen connection, master or slave
69
- def on(name)
70
- @current = send(name)
71
- yield(@current)
72
- ensure
73
- @current = nil
74
- end
75
-
76
- MASTER_METHODS.each do |meth|
77
- define_method(meth) do |*a, &b|
78
- (current || master).send(meth, *a, &b)
79
- end
80
- end
81
-
82
- SLAVE_METHODS.each do |meth|
83
- define_method(meth) do |*a, &b|
84
- (current || slave).send(meth, *a, &b)
85
- end
86
- end
87
-
88
- private
89
-
90
- def _connect(conn)
91
- case conn
92
- when String
93
- Redis.connect(:url => conn)
94
- else
95
- conn
96
- end
97
- end
98
-
99
- end