|
1 | 1 | # encoding: utf-8 |
2 | 2 |
|
3 | 3 | require File.dirname(__FILE__) + '/spec_helper' |
| 4 | +require 'connection_pool' |
4 | 5 |
|
5 | 6 | describe "redis" do |
6 | 7 | @redis_version = Gem::Version.new(Redis.new.info["redis_version"]) |
|
184 | 185 | expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({'foo'=>'1000', 'bar'=>'2000', 'baz' => nil}) |
185 | 186 | end |
186 | 187 |
|
| 188 | + it "should utilize connection_pool while using a namespace with mget" do |
| 189 | + memo = @namespaced |
| 190 | + connection_pool = ConnectionPool.new(size: 2, timeout: 2) { Redis.new db: 15 } |
| 191 | + @namespaced = Redis::Namespace.new(:ns, redis: connection_pool) |
| 192 | + |
| 193 | + expect(connection_pool).to receive(:with).and_call_original do |arg| |
| 194 | + expect(arg).to be(an_instance_of(Redis)) |
| 195 | + end.at_least(:once) |
| 196 | + |
| 197 | + @namespaced.set('foo', 1000) |
| 198 | + @namespaced.set('bar', 2000) |
| 199 | + expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' }) |
| 200 | + expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({'foo'=>'1000', 'bar'=>'2000', 'baz' => nil}) |
| 201 | + @redis.get('foo').should eq('bar') |
| 202 | + |
| 203 | + @namespaced = memo |
| 204 | + end |
| 205 | + |
187 | 206 | it "should be able to use a namespace with mset" do |
188 | 207 | @namespaced.mset('foo', '1000', 'bar', '2000') |
189 | 208 | expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' }) |
|
376 | 395 | expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"}) |
377 | 396 | end |
378 | 397 |
|
| 398 | + it "should utilize connection_pool while adding namepsace to multi blocks" do |
| 399 | + memo = @namespaced |
| 400 | + connection_pool = ConnectionPool.new(size: 2, timeout: 2) { Redis.new db: 15 } |
| 401 | + @namespaced = Redis::Namespace.new(:ns, redis: connection_pool) |
| 402 | + |
| 403 | + expect(connection_pool).to receive(:with).and_call_original do |arg| |
| 404 | + expect(arg).to be(an_instance_of(Redis)) |
| 405 | + end.at_least(:once) |
| 406 | + |
| 407 | + @namespaced.mapped_hmset "foo", {"key" => "value"} |
| 408 | + @namespaced.multi do |r| |
| 409 | + r.del "foo" |
| 410 | + r.mapped_hmset "foo", {"key1" => "value1"} |
| 411 | + end |
| 412 | + expect(@redis.get("foo")).to eq("bar") |
| 413 | + expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"}) |
| 414 | + |
| 415 | + @namespaced = memo |
| 416 | + end |
| 417 | + |
379 | 418 | it "should pass through multi commands without block" do |
380 | 419 | @namespaced.mapped_hmset "foo", {"key" => "value"} |
381 | 420 |
|
|
387 | 426 | expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"}) |
388 | 427 | end |
389 | 428 |
|
| 429 | + it "should utilize connection_pool while passing through multi commands without block" do |
| 430 | + memo = @namespaced |
| 431 | + connection_pool = ConnectionPool.new(size: 2, timeout: 2) { Redis.new db: 15 } |
| 432 | + @namespaced = Redis::Namespace.new(:ns, redis: connection_pool) |
| 433 | + |
| 434 | + expect(connection_pool).to receive(:with).and_call_original do |arg| |
| 435 | + expect(arg).to be(an_instance_of(Redis)) |
| 436 | + end.at_least(:once) |
| 437 | + |
| 438 | + @namespaced.mapped_hmset "foo", {"key" => "value"} |
| 439 | + |
| 440 | + @namespaced.multi |
| 441 | + @namespaced.del "foo" |
| 442 | + @namespaced.mapped_hmset "foo", {"key1" => "value1"} |
| 443 | + @namespaced.exec |
| 444 | + |
| 445 | + expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"}) |
| 446 | + expect(@redis.get("foo")).to eq("bar") |
| 447 | + |
| 448 | + @namespaced = memo |
| 449 | + end |
| 450 | + |
390 | 451 | it 'should return futures without attempting to remove namespaces' do |
391 | 452 | @namespaced.multi do |
392 | 453 | @future = @namespaced.keys('*') |
|
403 | 464 | expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"}) |
404 | 465 | end |
405 | 466 |
|
| 467 | + it "should utilize connection_pool while adding namespace to pipelined blocks" do |
| 468 | + memo = @namespaced |
| 469 | + connection_pool = ConnectionPool.new(size: 2, timeout: 2) { Redis.new db: 15 } |
| 470 | + @namespaced = Redis::Namespace.new(:ns, redis: connection_pool) |
| 471 | + |
| 472 | + expect(connection_pool).to receive(:with).and_call_original do |arg| |
| 473 | + expect(arg).to be(an_instance_of(Redis)) |
| 474 | + end.at_least(:once) |
| 475 | + |
| 476 | + @namespaced.mapped_hmset "foo", {"key" => "value"} |
| 477 | + @namespaced.pipelined do |r| |
| 478 | + r.del "foo" |
| 479 | + r.mapped_hmset "foo", {"key1" => "value1"} |
| 480 | + end |
| 481 | + expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"}) |
| 482 | + expect(@redis.get("foo")).to eq("bar") |
| 483 | + |
| 484 | + @namespaced = memo |
| 485 | + end |
| 486 | + |
406 | 487 | it "should returned response array from pipelined block" do |
407 | 488 | @namespaced.mset "foo", "bar", "key", "value" |
408 | 489 | result = @namespaced.pipelined do |r| |
|
0 commit comments