redpear 0.9.1 → 1.0.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.
- data/lib/redpear.rb +4 -5
- data/lib/redpear/model.rb +3 -2
- data/lib/redpear/schema.rb +4 -4
- data/lib/redpear/store.rb +5 -10
- data/lib/redpear/store/base.rb +2 -1
- data/lib/redpear/version.rb +3 -3
- metadata +16 -17
- data/lib/redpear/connection.rb +0 -99
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
|
-
|
25
|
-
|
25
|
+
require 'redpear/model/finders'
|
26
|
+
require 'redpear/model/expiration'
|
26
27
|
|
27
28
|
include Redpear::Schema
|
28
29
|
include Finders
|
data/lib/redpear/schema.rb
CHANGED
@@ -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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
data/lib/redpear/store/base.rb
CHANGED
data/lib/redpear/version.rb
CHANGED
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.
|
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:
|
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/
|
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/
|
144
|
-
- lib/redpear/
|
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/
|
151
|
-
- lib/redpear/
|
152
|
-
- lib/redpear/
|
153
|
-
- lib/redpear/
|
154
|
-
- lib/redpear/
|
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.
|
175
|
+
rubygems_version: 1.8.25
|
177
176
|
signing_key:
|
178
177
|
specification_version: 3
|
179
178
|
summary: Redpear, a Redis ORM
|
data/lib/redpear/connection.rb
DELETED
@@ -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
|