superfeedr-em-redis 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,37 +18,7 @@ module EventMachine
18
18
  ASTERISK = "*".freeze
19
19
  DELIM = "\r\n".freeze
20
20
 
21
- BULK_COMMANDS = {
22
- "set" => true,
23
- "setnx" => true,
24
- "rpush" => true,
25
- "lpush" => true,
26
- "lset" => true,
27
- "lrem" => true,
28
- "sadd" => true,
29
- "srem" => true,
30
- "sismember" => true,
31
- "echo" => true,
32
- "getset" => true,
33
- "smove" => true,
34
- "zadd" => true,
35
- "zincrby" => true,
36
- "zrem" => true,
37
- "zscore" => true,
38
- "hget" => true,
39
- "hdel" => true,
40
- "hexists" => true
41
- }
42
-
43
- MULTI_BULK_COMMANDS = {
44
- "mset" => true,
45
- "msetnx" => true,
46
- "hset" => true,
47
- # these aliases aren't in redis gem
48
- "multi_get" => true
49
- }
50
-
51
- BOOLEAN_PROCESSOR = lambda{|r| %w(1 OK).include? r.to_s }
21
+ BOOLEAN_PROCESSOR = lambda{|r| r == 1 }
52
22
 
53
23
  REPLY_PROCESSOR = {
54
24
  "exists" => BOOLEAN_PROCESSOR,
@@ -186,11 +156,11 @@ module EventMachine
186
156
  def sort(key, options={}, &blk)
187
157
  cmd = ["SORT"]
188
158
  cmd << key
189
- cmd << "BY #{options[:by]}" if options[:by]
190
- cmd << "GET #{[options[:get]].flatten * ' GET '}" if options[:get]
191
- cmd << "#{options[:order]}" if options[:order]
192
- cmd << "LIMIT #{options[:limit].join(' ')}" if options[:limit]
193
- call_command(cmd, &blk)
159
+ cmd << ["BY", options[:by]] if options[:by]
160
+ cmd << [options[:get]].flatten.map { |key| ["GET", key] } if options[:get]
161
+ cmd << options[:order].split(/\s+/) if options[:order]
162
+ cmd << ["LIMIT", options[:limit]] if options[:limit]
163
+ call_command(cmd.flatten, &blk)
194
164
  end
195
165
 
196
166
  def incr(key, increment = nil, &blk)
@@ -296,26 +266,16 @@ module EventMachine
296
266
  argv = argv.dup
297
267
 
298
268
  argv[0] = argv[0].to_s.downcase
299
- if MULTI_BULK_COMMANDS[argv[0]]
300
- command = ""
301
- command << "*#{argv.size}\r\n"
302
- argv.each do |a|
303
- a = a.to_s
304
- command << "$#{get_size(a)}\r\n"
305
- command << a
306
- command << "\r\n"
307
- end
308
- else
309
- command = ""
310
- bulk = nil
311
- argv[0] = ALIASES[argv[0]] if ALIASES[argv[0]]
312
- raise "#{argv[0]} command is disabled" if DISABLED_COMMANDS[argv[0]]
313
- if BULK_COMMANDS[argv[0]] and argv.length > 1
314
- bulk = argv[-1].to_s
315
- argv[-1] = get_size(bulk)
316
- end
317
- command << "#{argv.join(' ')}\r\n"
318
- command << "#{bulk}\r\n" if bulk
269
+ argv[0] = ALIASES[argv[0]] if ALIASES[argv[0]]
270
+ raise "#{argv[0]} command is disabled" if DISABLED_COMMANDS[argv[0]]
271
+
272
+ command = ""
273
+ command << "*#{argv.size}\r\n"
274
+ argv.each do |a|
275
+ a = a.to_s
276
+ command << "$#{get_size(a)}\r\n"
277
+ command << a
278
+ command << "\r\n"
319
279
  end
320
280
 
321
281
  @logger.debug { "*** sending: #{command}" } if @logger
@@ -325,23 +285,6 @@ module EventMachine
325
285
  end
326
286
  end
327
287
 
328
- def call_commands(argvs, &blk)
329
- pending = 0
330
- results = []
331
- check = lambda {
332
- blk.call(results) if pending < 1
333
- }
334
- argvs.each do |argv|
335
- call_command(argv) { |result|
336
- results << result
337
- pending -= 1
338
- check.call
339
- }
340
- pending += 1
341
- end
342
- check.call
343
- end
344
-
345
288
  ##
346
289
  # errors
347
290
  #########################
@@ -390,6 +333,7 @@ module EventMachine
390
333
  err.code = code
391
334
  raise err, "Redis server returned error code: #{code}"
392
335
  end
336
+ @values = []
393
337
 
394
338
  # These commands should be first
395
339
  auth_and_select_db
@@ -405,6 +349,7 @@ module EventMachine
405
349
  @logger.debug { "Connected to #{@host}:#{@port}" } if @logger
406
350
 
407
351
  @redis_callbacks = []
352
+ @previous_multibulks = []
408
353
  @multibulk_n = false
409
354
  @reconnecting = false
410
355
  @connected = true
@@ -464,6 +409,9 @@ module EventMachine
464
409
  if multibulk_count == -1 || multibulk_count == 0
465
410
  dispatch_response([])
466
411
  else
412
+ if @multibulk_n
413
+ @previous_multibulks << [@multibulk_n, @multibulk_values]
414
+ end
467
415
  @multibulk_n = multibulk_count
468
416
  @multibulk_values = []
469
417
  end
@@ -481,18 +429,22 @@ module EventMachine
481
429
 
482
430
  if @multibulk_n == 0
483
431
  value = @multibulk_values
484
- @multibulk_n = false
432
+ @multibulk_n,@multibulk_values = @previous_multibulks.pop
433
+ if @multibulk_n
434
+ dispatch_response(value)
435
+ return
436
+ end
485
437
  else
486
438
  return
487
439
  end
488
440
  end
489
441
 
490
442
  callback = @redis_callbacks.shift
491
- if callback.kind_of?(Array) && callback.length == 2
443
+ if callback.length == 2
492
444
  processor, blk = callback
493
445
  value = processor.call(value) if processor
494
446
  blk.call(value) if blk
495
- elsif callback.kind_of?(Array) && callback.length == 3
447
+ else
496
448
  processor, pipeline_count, blk = callback
497
449
  value = processor.call(value) if processor
498
450
  @values << value
@@ -505,11 +457,6 @@ module EventMachine
505
457
  end
506
458
  end
507
459
 
508
- def start_multibulk(multibulk_count)
509
- @multibulk_n = multibulk_count
510
- @multibulk_values = []
511
- end
512
-
513
460
  def unbind
514
461
  @logger.debug { "Disconnected" } if @logger
515
462
  if @connected || @reconnecting
@@ -0,0 +1,3 @@
1
+ module EMRedis
2
+ VERSION = '0.3.0' unless defined? ::EMRedis::VERSION
3
+ end
data/lib/em-redis.rb CHANGED
@@ -1,47 +1,2 @@
1
-
2
- module EMRedis
3
-
4
- # :stopdoc:
5
- VERSION = '0.2.7'
6
- LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
- PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
- # :startdoc:
9
-
10
- # Returns the version string for the library.
11
- #
12
- def self.version
13
- VERSION
14
- end
15
-
16
- # Returns the library path for the module. If any arguments are given,
17
- # they will be joined to the end of the libray path using
18
- # <tt>File.join</tt>.
19
- #
20
- def self.libpath( *args )
21
- args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
22
- end
23
-
24
- # Returns the lpath for the module. If any arguments are given,
25
- # they will be joined to the end of the path using
26
- # <tt>File.join</tt>.
27
- #
28
- def self.path( *args )
29
- args.empty? ? PATH : ::File.join(PATH, args.flatten)
30
- end
31
-
32
- # Utility method used to require all files ending in .rb that lie in the
33
- # directory below this file that has the same name as the filename passed
34
- # in. Optionally, a specific _directory_ name can be passed in such that
35
- # the _filename_ does not have to be equivalent to the directory.
36
- #
37
- def self.require_all_libs_relative_to( fname, dir = nil )
38
- dir ||= ::File.basename(fname, '.*')
39
- search_me = ::File.expand_path(
40
- ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
41
-
42
- Dir.glob(search_me).sort.each {|rb| require rb}
43
- end
44
-
45
- end # module EMRedis
46
-
47
- EMRedis.require_all_libs_relative_to(__FILE__)
1
+ require File.expand_path('../em-redis/version', __FILE__)
2
+ require File.expand_path('../em-redis/redis_protocol', __FILE__)
metadata CHANGED
@@ -1,23 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superfeedr-em-redis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 2
9
- - 7
10
- version: 0.2.7
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jonathan Broad
14
13
  - Eugene Pimenov
15
- - Stephan Maka
14
+ - Julien Genestoux
16
15
  autorequire:
17
16
  bindir: bin
18
17
  cert_chain: []
19
18
 
20
- date: 2010-06-22 00:00:00 +02:00
19
+ date: 2011-02-20 00:00:00 -05:00
21
20
  default_executable:
22
21
  dependencies:
23
22
  - !ruby/object:Gem::Dependency
@@ -28,91 +27,47 @@ dependencies:
28
27
  requirements:
29
28
  - - ">="
30
29
  - !ruby/object:Gem::Version
31
- hash: 59
32
30
  segments:
33
31
  - 0
34
- - 12
35
- - 10
36
- version: 0.12.10
32
+ version: "0"
37
33
  type: :runtime
38
34
  version_requirements: *id001
39
35
  - !ruby/object:Gem::Dependency
40
- name: bacon
36
+ name: bundler
41
37
  prerelease: false
42
38
  requirement: &id002 !ruby/object:Gem::Requirement
43
39
  none: false
44
40
  requirements:
45
- - - ">="
41
+ - - ~>
46
42
  - !ruby/object:Gem::Version
47
- hash: 19
48
43
  segments:
49
44
  - 1
50
- - 1
51
45
  - 0
52
- version: 1.1.0
46
+ - rc
47
+ - 6
48
+ version: 1.0.rc.6
53
49
  type: :development
54
50
  version_requirements: *id002
55
- - !ruby/object:Gem::Dependency
56
- name: em-spec
57
- prerelease: false
58
- requirement: &id003 !ruby/object:Gem::Requirement
59
- none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- hash: 21
64
- segments:
65
- - 0
66
- - 2
67
- - 1
68
- version: 0.2.1
69
- type: :development
70
- version_requirements: *id003
71
- - !ruby/object:Gem::Dependency
72
- name: bones
73
- prerelease: false
74
- requirement: &id004 !ruby/object:Gem::Requirement
75
- none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 21
80
- segments:
81
- - 3
82
- - 4
83
- - 1
84
- version: 3.4.1
85
- type: :development
86
- version_requirements: *id004
87
51
  description: An eventmachine-based implementation of the Redis protocol
88
- email: stephan@spaceboyz.net
52
+ email:
89
53
  executables: []
90
54
 
91
55
  extensions: []
92
56
 
93
- extra_rdoc_files:
94
- - History.txt
95
- - README.rdoc
57
+ extra_rdoc_files: []
58
+
96
59
  files:
97
- - History.txt
98
- - README.rdoc
99
- - Rakefile
100
- - dump.rdb
101
- - lib/em-redis.rb
102
60
  - lib/em-redis/redis_protocol.rb
103
- - spec/live_redis_protocol_spec.rb
104
- - spec/redis_commands_spec.rb
105
- - spec/redis_commands_spec.rb.orig
106
- - spec/redis_protocol_spec.rb
107
- - spec/test_helper.rb
61
+ - lib/em-redis/version.rb
62
+ - lib/em-redis.rb
63
+ - History.txt
108
64
  has_rdoc: true
109
- homepage: http://github.com/astro/em-redis
65
+ homepage: http://github.com/superfeedr/em-redis
110
66
  licenses: []
111
67
 
112
68
  post_install_message:
113
- rdoc_options:
114
- - --main
115
- - README.rdoc
69
+ rdoc_options: []
70
+
116
71
  require_paths:
117
72
  - lib
118
73
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -120,7 +75,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
75
  requirements:
121
76
  - - ">="
122
77
  - !ruby/object:Gem::Version
123
- hash: 3
124
78
  segments:
125
79
  - 0
126
80
  version: "0"
@@ -129,13 +83,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
83
  requirements:
130
84
  - - ">="
131
85
  - !ruby/object:Gem::Version
132
- hash: 3
133
86
  segments:
134
87
  - 0
135
88
  version: "0"
136
89
  requirements: []
137
90
 
138
- rubyforge_project: superfeedr-em-redis
91
+ rubyforge_project:
139
92
  rubygems_version: 1.3.7
140
93
  signing_key:
141
94
  specification_version: 3
data/README.rdoc DELETED
@@ -1,85 +0,0 @@
1
- == EM-REDIS
2
-
3
- == DESCRIPTION:
4
-
5
- An EventMachine[http://rubyeventmachine.com/] based library for interacting with the very cool Redis[http://code.google.com/p/redis/] data store by Salvatore 'antirez' Sanfilippo.
6
- Modeled after eventmachine's implementation of the memcached protocol, and influenced by Ezra Zygmuntowicz's {redis-rb}[http://github.com/ezmobius/redis-rb/tree/master] library (distributed as part of Redis).
7
-
8
- This library is only useful when used as part of an application that relies on
9
- Event Machine's event loop. It implements an EM-based client protocol, which
10
- leverages the non-blocking nature of the EM interface to achieve significant
11
- parallelization without threads.
12
-
13
-
14
- == FEATURES/PROBLEMS:
15
-
16
- Implements most Redis commands (see {the list of available commands here}[http://code.google.com/p/redis/wiki/CommandReference] with the notable
17
- exception of MONITOR.
18
-
19
- == SYNOPSIS:
20
-
21
- Like any Deferrable eventmachine-based protocol implementation, using EM-Redis involves making calls and passing blocks that serve as callbacks when the call returns.
22
-
23
- require 'em-redis'
24
-
25
- EM.run do
26
- redis = EM::Protocols::Redis.connect
27
- redis.errback do |code|
28
- puts "Error code: #{code}"
29
- end
30
- redis.set "a", "foo" do |response|
31
- redis.get "a" do |response|
32
- puts response
33
- end
34
- end
35
- # We get pipelining for free
36
- redis.set("b", "bar")
37
- redis.get("a") do |response|
38
- puts response # will be foo
39
- end
40
- end
41
-
42
- To run tests on a Redis server (currently compatible with 1.3)
43
-
44
- rake
45
-
46
- Because the EM::Protocol::Memcached code used Bacon for testing, test code is
47
- currently in the form of bacon specs.
48
-
49
- == REQUIREMENTS:
50
-
51
- * Redis (download[http://code.google.com/p/redis/downloads/list])
52
-
53
- == INSTALL:
54
-
55
- sudo gem install em-redis
56
-
57
- == LICENSE:
58
-
59
- (The MIT License)
60
-
61
- Copyright (c) 2008, 2009
62
-
63
- Permission is hereby granted, free of charge, to any person obtaining
64
- a copy of this software and associated documentation files (the
65
- 'Software'), to deal in the Software without restriction, including
66
- without limitation the rights to use, copy, modify, merge, publish,
67
- distribute, sublicense, and/or sell copies of the Software, and to
68
- permit persons to whom the Software is furnished to do so, subject to
69
- the following conditions:
70
-
71
- The above copyright notice and this permission notice shall be
72
- included in all copies or substantial portions of the Software.
73
-
74
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
75
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
76
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
77
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
78
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
79
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
80
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81
-
82
- == CREDIT
83
-
84
- by Jonathan Broad (http://www.relativepath.org)
85
-
data/Rakefile DELETED
@@ -1,41 +0,0 @@
1
- # Look in the tasks/setup.rb file for the various options that can be
2
- # configured in this Rakefile. The .rake files in the tasks directory
3
- # are where the options are used.
4
-
5
- begin
6
- require 'bones'
7
- rescue LoadError
8
- abort '### Please install the "bones" gem ###'
9
- end
10
-
11
- ensure_in_path 'lib'
12
- require 'em-redis'
13
-
14
- task :default => ['redis:test']
15
-
16
- Bones {
17
- name 'superfeedr-em-redis'
18
- authors ['Jonathan Broad', 'Eugene Pimenov', 'Stephan Maka']
19
- email 'stephan@spaceboyz.net'
20
- url 'http://github.com/astro/em-redis'
21
- summary 'An eventmachine-based implementation of the Redis protocol'
22
- description summary
23
- version EMRedis::VERSION
24
-
25
- readme_file 'README.rdoc'
26
- ignore_file '.gitignore'
27
-
28
- depend_on 'eventmachine', '>=0.12.10'
29
-
30
- depend_on "bacon", :development => true
31
- depend_on "em-spec", :development => true
32
- }
33
-
34
- namespace :redis do
35
- desc "Test em-redis against a live Redis"
36
- task :test do
37
- sh "bacon spec/live_redis_protocol_spec.rb spec/redis_commands_spec.rb spec/redis_protocol_spec.rb"
38
- end
39
- end
40
-
41
- # EOF
data/dump.rdb DELETED
Binary file