memcache-client 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -1,3 +1,10 @@
1
+ = 1.5.0
2
+
3
+ * Add MemCache#flush_all command. Patch #13019 and bug #10503. Patches
4
+ submitted by Sebastian Delmont and Rick Olson.
5
+ * Type-cast data returned by MemCache#stats. Patch #10505 submitted by
6
+ Sebastian Delmont.
7
+
1
8
  = 1.4.0
2
9
 
3
10
  * Fix bug #10371, #set does not check response for server errors.
@@ -42,7 +42,7 @@ class MemCache
42
42
  ##
43
43
  # The version of MemCache you are using.
44
44
 
45
- VERSION = '1.4.0'
45
+ VERSION = '1.5.0'
46
46
 
47
47
  ##
48
48
  # Default options for the cache object.
@@ -365,6 +365,31 @@ class MemCache
365
365
  @mutex.unlock if @multithread
366
366
  end
367
367
 
368
+ ##
369
+ # Flush the cache from all memcache servers.
370
+
371
+ def flush_all
372
+ raise MemCacheError, 'No active servers' unless active?
373
+ raise MemCacheError, "Update of readonly cache" if @readonly
374
+ begin
375
+ @mutex.lock if @multithread
376
+ @servers.each do |server|
377
+ begin
378
+ sock = server.socket
379
+ raise MemCacheError, "No connection to server" if sock.nil?
380
+ sock.write "flush_all\r\n"
381
+ result = sock.gets
382
+ raise MemCacheError, $2.strip if result =~ /^(SERVER_)?ERROR(.*)/
383
+ rescue SocketError, SystemCallError, IOError => err
384
+ server.close
385
+ raise MemCacheError, err.message
386
+ end
387
+ end
388
+ ensure
389
+ @mutex.unlock if @multithread
390
+ end
391
+ end
392
+
368
393
  ##
369
394
  # Reset the connection to all memcache servers. This should be called if
370
395
  # there is a problem with a cache lookup that might have left the connection
@@ -384,26 +409,26 @@ class MemCache
384
409
  #
385
410
  # >> pp CACHE.stats
386
411
  # {"localhost:11211"=>
387
- # {"bytes"=>"4718",
388
- # "pid"=>"20188",
389
- # "connection_structures"=>"4",
390
- # "time"=>"1162278121",
391
- # "pointer_size"=>"32",
392
- # "limit_maxbytes"=>"67108864",
393
- # "cmd_get"=>"14532",
412
+ # {"bytes"=>4718,
413
+ # "pid"=>20188,
414
+ # "connection_structures"=>4,
415
+ # "time"=>1162278121,
416
+ # "pointer_size"=>32,
417
+ # "limit_maxbytes"=>67108864,
418
+ # "cmd_get"=>14532,
394
419
  # "version"=>"1.2.0",
395
- # "bytes_written"=>"432583",
396
- # "cmd_set"=>"32",
397
- # "get_misses"=>"0",
398
- # "total_connections"=>"19",
399
- # "curr_connections"=>"3",
400
- # "curr_items"=>"4",
401
- # "uptime"=>"1557",
402
- # "get_hits"=>"14532",
403
- # "total_items"=>"32",
404
- # "rusage_system"=>"0.313952",
405
- # "rusage_user"=>"0.119981",
406
- # "bytes_read"=>"190619"}}
420
+ # "bytes_written"=>432583,
421
+ # "cmd_set"=>32,
422
+ # "get_misses"=>0,
423
+ # "total_connections"=>19,
424
+ # "curr_connections"=>3,
425
+ # "curr_items"=>4,
426
+ # "uptime"=>1557,
427
+ # "get_hits"=>14532,
428
+ # "total_items"=>32,
429
+ # "rusage_system"=>0.313952,
430
+ # "rusage_user"=>0.119981,
431
+ # "bytes_read"=>190619}}
407
432
  # => nil
408
433
 
409
434
  def stats
@@ -418,12 +443,27 @@ class MemCache
418
443
  begin
419
444
  sock.write "stats\r\n"
420
445
  stats = {}
421
- while line = sock.gets
446
+ while line = sock.gets do
422
447
  break if line == "END\r\n"
423
- line =~ /^STAT ([\w]+) ([\d.]+)/
424
- stats[$1] = $2
448
+ if line =~ /^STAT ([\w]+) ([\w\.\:]+)/ then
449
+ name, value = $1, $2
450
+ stats[name] = case name
451
+ when 'version'
452
+ value
453
+ when 'rusage_user', 'rusage_system' then
454
+ seconds, microseconds = value.split(/:/, 2)
455
+ microseconds ||= 0
456
+ Float(seconds) + (Float(microseconds) / 1_000_000)
457
+ else
458
+ if value =~ /^\d+$/ then
459
+ value.to_i
460
+ else
461
+ value
462
+ end
463
+ end
464
+ end
425
465
  end
426
- server_stats["#{server.host}:#{server.port}"] = stats.clone
466
+ server_stats["#{server.host}:#{server.port}"] = stats
427
467
  rescue SocketError, SystemCallError, IOError => err
428
468
  server.close
429
469
  raise MemCacheError, err.message
@@ -507,19 +507,6 @@ class TestMemCache < Test::Unit::TestCase
507
507
  assert_equal expected, server.socket.written.string
508
508
  end
509
509
 
510
- def test_set
511
- server = FakeServer.new
512
- server.socket.data.write "STORED\r\n"
513
- server.socket.data.rewind
514
- @cache.servers = []
515
- @cache.servers << server
516
-
517
- @cache.set 'key', 'value'
518
-
519
- expected = "set my_namespace:key 0 0 9\r\n\004\b\"\nvalue\r\n"
520
- assert_equal expected, server.socket.written.string
521
- end
522
-
523
510
  def test_set_expiry
524
511
  server = FakeServer.new
525
512
  server.socket.data.write "STORED\r\n"
@@ -632,9 +619,43 @@ class TestMemCache < Test::Unit::TestCase
632
619
  assert_equal 'Update of readonly cache', e.message
633
620
  end
634
621
 
635
- def test_stats
622
+ def test_delete
623
+ server = FakeServer.new
624
+ @cache.servers = []
625
+ @cache.servers << server
626
+
627
+ @cache.delete 'key'
628
+
629
+ expected = "delete my_namespace:key 0\r\n"
630
+ assert_equal expected, server.socket.written.string
631
+ end
632
+
633
+ def test_delete_with_expiry
634
+ server = FakeServer.new
635
+ @cache.servers = []
636
+ @cache.servers << server
637
+
638
+ @cache.delete 'key', 300
639
+
640
+ expected = "delete my_namespace:key 300\r\n"
641
+ assert_equal expected, server.socket.written.string
642
+ end
643
+
644
+ def test_flush_all
645
+ @cache.servers = []
646
+ 3.times { @cache.servers << FakeServer.new }
647
+
648
+ @cache.flush_all
649
+
650
+ expected = "flush_all\r\n"
651
+ @cache.servers.each do |server|
652
+ assert_equal expected, server.socket.written.string
653
+ end
654
+ end
655
+
656
+ def test_flush_all_failure
636
657
  socket = FakeSocket.new
637
- socket.data.write "STAT pid 20188\r\nSTAT total_items 32\r\rEND\r\n"
658
+ socket.data.write "ERROR\r\n"
638
659
  socket.data.rewind
639
660
  server = FakeServer.new socket
640
661
  def server.host() "localhost"; end
@@ -643,7 +664,30 @@ class TestMemCache < Test::Unit::TestCase
643
664
  @cache.servers = []
644
665
  @cache.servers << server
645
666
 
646
- expected = {"localhost:11211"=>{"pid"=>"20188", "total_items"=>"32"}}
667
+ assert_raise MemCache::MemCacheError do
668
+ @cache.flush_all
669
+ end
670
+
671
+ assert_equal "flush_all\r\n", socket.written.string
672
+ end
673
+
674
+ def test_stats
675
+ socket = FakeSocket.new
676
+ socket.data.write "STAT pid 20188\r\nSTAT total_items 32\r\nSTAT version 1.2.3\r\nSTAT rusage_user 1:300\r\nSTAT dummy ok\r\nEND\r\n"
677
+ socket.data.rewind
678
+ server = FakeServer.new socket
679
+ def server.host() 'localhost'; end
680
+ def server.port() 11211; end
681
+
682
+ @cache.servers = []
683
+ @cache.servers << server
684
+
685
+ expected = {
686
+ 'localhost:11211' => {
687
+ 'pid' => 20188, 'total_items' => 32, 'version' => '1.2.3',
688
+ 'rusage_user' => 1.0003, 'dummy' => 'ok'
689
+ }
690
+ }
647
691
  assert_equal expected, @cache.stats
648
692
 
649
693
  assert_equal "stats\r\n", socket.written.string
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4.3
3
3
  specification_version: 1
4
4
  name: memcache-client
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.4.0
7
- date: 2007-07-30 00:00:00 -07:00
6
+ version: 1.5.0
7
+ date: 2007-08-13 00:00:00 -07:00
8
8
  summary: A Ruby memcached client
9
9
  require_paths:
10
10
  - lib
@@ -31,6 +31,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
31
31
  platform: ruby
32
32
  signing_key:
33
33
  cert_chain:
34
+ - |
35
+ -----BEGIN CERTIFICATE-----
36
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
37
+ YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
38
+ ZXQwHhcNMDcwODE0MDAwMjIzWhcNMDgwODEzMDAwMjIzWjBBMRAwDgYDVQQDDAdk
39
+ cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
40
+ FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDVZUNKmnp8LrkM
41
+ bQd5ZrcTV1R7woai4clBLUjH3DL47r+f6d5dz+gJUegZ3RKWdSvOfaRmXFkr2+nv
42
+ vc6uzcxk9w1uN5Z3w+BCeKtsUR8EtUhH8b26HDNGDeuoTX1gEgm4DacBh1/Ib+SQ
43
+ PxLVkFnWiCekGvL7jzecw6UwADn49Ag4NxIvpN0ttsYCQFMDuqzdISjurbb3dZ2z
44
+ OsaDqdW29c3Jed816kVhOzRZ2EC4BExPtEN6xZCwab6f9tzJT+Atea7PRFLm/T7t
45
+ QFBPGC2XjPUXJxTyz+8PEDDb2PXeZwPSDIysq1tzB55A3rE1a5pLvnBfek5KjC25
46
+ 0wuuKuxlAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
47
+ BBStuxfp/gfzqL+3k7tFe8gVU9zpvDANBgkqhkiG9w0BAQUFAAOCAQEAvnmUelUN
48
+ s9f/VasT9mZV4tIP3sKi0uqyq9i7vtDgCNFw0BAKNxa6ybO1CrBBnjDMa4hvhrW8
49
+ qCLkx7BFHGV/eWR3pdwcLAS8cLuEib75nuG1lbG2yIvGSYTyQ/oxbmuUAZxpavK2
50
+ 101OludXvBC9hpA4Qz3UhJYBdtT8TuztiFGLzhCJusjUD7I6Y+TrrTPkBGceVVyY
51
+ hx8aJk+44+jvzgsTi4MyrRo4lAGsQxFa1f1IBuEgqNPdML31yGO0QKof+IqPiVNo
52
+ HsCQoSWkgfQE0DHTgx+hWkF2d10+54I4aM9tIROeGACQemcj0IRf3v7Au8I+6PWl
53
+ 3E1oHz01aNcUFA==
54
+ -----END CERTIFICATE-----
55
+
34
56
  post_install_message:
35
57
  authors:
36
58
  - Eric Hodel
@@ -77,5 +99,5 @@ dependencies:
77
99
  requirements:
78
100
  - - ">="
79
101
  - !ruby/object:Gem::Version
80
- version: 1.2.2
102
+ version: 1.3.0
81
103
  version:
Binary file