Skip to content
This repository

add gzip compressor #303

Merged
merged 1 commit into from over 1 year ago

2 participants

Tyler Kellen Mike Perham
Tyler Kellen

added for ease-of-use with nginx serving gzipped data directly from memcached

Mike Perham
Owner

Tests?

Tyler Kellen

Added. I believe the test is set up correctly, can you confirm?

Mike Perham mperham commented on the diff December 10, 2012
test/test_compressor.rb
... ...
@@ -34,3 +34,15 @@ def self.decompress(data)
34 34
     end
35 35
   end
36 36
 end
  37
+
  38
+describe 'GzipCompressor' do
  39
+
  40
+  should 'compress and uncompress data using Zlib::GzipWriter/Reader' do
  41
+    memcached(19127,nil,{:compress=>true,:compressor=>Dalli::GzipCompressor}) do |dc|
1
Mike Perham Owner
mperham added a note December 10, 2012

Change :compressor to :compessor and watch the spec still pass. You need to set some expectations to verify your methods are being called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Tyler Kellen

Roger that, please see the test now.

Mike Perham
Owner

Did you forget to push? There's no new commit.

Tyler Kellen

Nope, there is just one extra line:
tkellen@98a1238#L1R44

Tyler Kellen

To be more precise, I force pushed over my existing branch to update the PR.

Mike Perham mperham merged commit 4252f98 into from December 10, 2012
Mike Perham mperham closed this December 10, 2012
Mike Perham
Owner

Got it, thank you!

Mike Perham
Owner

Oh, if you want to update the changelog with a note about nginx / gzip compatibility, I bet some people would find that useful.

Tyler Kellen

Roger that, coming up.

Tyler Kellen

Do you want it listed in History.md under 2.6.0?

Mike Perham
Owner

That would be fine.

Tyler Kellen

Not sure why, but the PR button isn't showing up for this, feel free to grab it manually!
https://github.com/tkellen/dalli/tree/docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 10, 2012
Tyler Kellen add gzip compressor 98a1238
This page is out of date. Refresh to see the latest.
16  lib/dalli/compressor.rb
... ...
@@ -1,4 +1,5 @@
1 1
 require 'zlib'
  2
+require 'stringio'
2 3
 
3 4
 module Dalli
4 5
   class Compressor
@@ -10,4 +11,19 @@ def self.decompress(data)
10 11
       Zlib::Inflate.inflate(data)
11 12
     end
12 13
   end
  14
+
  15
+  class GzipCompressor
  16
+    def self.compress(data)
  17
+      io = StringIO.new("w")
  18
+      gz = Zlib::GzipWriter.new(io)
  19
+      gz.write(data)
  20
+      gz.close
  21
+      io.string
  22
+    end
  23
+
  24
+    def self.decompress(data)
  25
+      io = StringIO.new(data, "rb")
  26
+      Zlib::GzipReader.new(io).read
  27
+    end
  28
+  end
13 29
 end
13  test/test_compressor.rb
@@ -34,3 +34,16 @@ def self.decompress(data)
34 34
     end
35 35
   end
36 36
 end
  37
+
  38
+describe 'GzipCompressor' do
  39
+
  40
+  should 'compress and uncompress data using Zlib::GzipWriter/Reader' do
  41
+    memcached(19127,nil,{:compress=>true,:compressor=>Dalli::GzipCompressor}) do |dc|
  42
+      data = (0...1025).map{65.+(rand(26)).chr}.join
  43
+      assert dc.set("test", data)
  44
+      assert_equal Dalli::GzipCompressor, dc.instance_variable_get('@ring').servers.first.compressor
  45
+      assert_equal(data, dc.get("test"))
  46
+    end
  47
+  end
  48
+
  49
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.