redis 1.0.7 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,13 @@
1
1
  class Redis
2
- class Pipeline < Client
3
- BUFFER_SIZE = 50_000
2
+ class Pipeline
3
+ attr :commands
4
4
 
5
- def initialize(redis)
6
- @redis = redis
5
+ def initialize
7
6
  @commands = []
8
7
  end
9
8
 
10
- def call_command(command)
11
- @commands << command
12
- end
13
-
14
- def execute
15
- return if @commands.empty?
16
- @redis.call_command(@commands)
9
+ def call(*args)
10
+ @commands << args
17
11
  end
18
12
  end
19
13
  end
@@ -1,16 +1,89 @@
1
1
  class Redis
2
- class Subscription
2
+ class SubscribedClient
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+
7
+ def call(command, *args)
8
+ @client.call_async(command, *args)
9
+ end
10
+
11
+ def subscribe(*channels, &block)
12
+ @client.call_async(:subscribe, *channels)
13
+
14
+ sub = Subscription.new(&block)
15
+
16
+ begin
17
+ loop do
18
+ type, channel, message = @client.read
19
+ sub.callbacks[type].call(channel, message)
20
+ break if type == "unsubscribe" && message == 0
21
+ end
22
+ ensure
23
+ @client.call_async(:unsubscribe)
24
+ end
25
+ end
26
+
27
+ def unsubscribe(*channels)
28
+ @client.call_async(:unsubscribe, *channels)
29
+ @client
30
+ end
31
+
32
+ def psubscribe(*channels, &block)
33
+ @client.call_async(:psubscribe, *channels)
34
+
35
+ sub = Subscription.new(&block)
36
+
37
+ begin
38
+ loop do
39
+ type, pattern, channel, message = @client.read
40
+ sub.callbacks[type].call(pattern, channel, message)
41
+ break if type == "punsubscribe" && channel == 0
42
+ end
43
+ ensure
44
+ @client.call_async(:punsubscribe)
45
+ end
46
+ end
47
+
48
+ def punsubscribe(*channels)
49
+ @client.call_async(:punsubscribe, *channels)
50
+ @client
51
+ end
52
+ end
53
+
54
+ class Subscription
55
+ attr :callbacks
56
+
57
+ def initialize
58
+ @callbacks = Hash.new do |hash, key|
59
+ hash[key] = lambda { |*_| }
60
+ end
61
+
62
+ yield(self)
63
+ end
64
+
3
65
  def subscribe(&block)
4
- if block_given? then @subscribe = block else @subscribe end
66
+ @callbacks["subscribe"] = block
67
+ end
68
+
69
+ def unsubscribe(&block)
70
+ @callbacks["unsubscribe"] = block
71
+ end
72
+
73
+ def message(&block)
74
+ @callbacks["message"] = block
75
+ end
76
+
77
+ def psubscribe(&block)
78
+ @callbacks["psubscribe"] = block
5
79
  end
6
-
7
- def unsubscribe(&block)
8
- if block_given? then @unsubscribe = block else @unsubscribe end
80
+
81
+ def punsubscribe(&block)
82
+ @callbacks["punsubscribe"] = block
9
83
  end
10
-
11
- def message(&block)
12
- if block_given? then @message = block else @message end
84
+
85
+ def pmessage(&block)
86
+ @callbacks["pmessage"] = block
13
87
  end
14
-
15
88
  end
16
- end
89
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
- - 1
6
+ - 2
7
7
  - 0
8
- - 7
9
- version: 1.0.7
8
+ - 0
9
+ - rc1
10
+ version: 2.0.0.rc1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ezra Zygmuntowicz
@@ -19,7 +20,7 @@ autorequire: redis
19
20
  bindir: bin
20
21
  cert_chain: []
21
22
 
22
- date: 2010-04-28 00:00:00 -03:00
23
+ date: 2010-04-26 00:00:00 -03:00
23
24
  default_executable:
24
25
  dependencies: []
25
26
 
@@ -37,7 +38,6 @@ files:
37
38
  - Rakefile
38
39
  - lib/edis.rb
39
40
  - lib/redis/client.rb
40
- - lib/redis/dist_redis.rb
41
41
  - lib/redis/distributed.rb
42
42
  - lib/redis/hash_ring.rb
43
43
  - lib/redis/pipeline.rb
@@ -63,11 +63,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
63
  version: "0"
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - ">"
67
67
  - !ruby/object:Gem::Version
68
68
  segments:
69
- - 0
70
- version: "0"
69
+ - 1
70
+ - 3
71
+ - 1
72
+ version: 1.3.1
71
73
  requirements: []
72
74
 
73
75
  rubyforge_project:
@@ -1,16 +0,0 @@
1
- Redis.deprecate %q{"redis/dist_redis" is deprecated. Require "redis/distributed" and replace DistRedis for Redis::Distributed.}, caller[0]
2
-
3
- require "redis/hash_ring"
4
- require "redis/distributed"
5
-
6
- class Redis
7
- class DistRedis < Redis::Distributed
8
- def initialize(*args)
9
- Redis.deprecate "DistRedis is deprecated in favor of Redis::Distributed.", caller[1]
10
- super(*args)
11
- end
12
- end
13
- end
14
-
15
- # For backwards compatibility
16
- DistRedis = Redis::DistRedis