spymemcached 0.1.2-java → 0.2.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -15,7 +15,7 @@ module ActiveSupport
15
15
 
16
16
  def read(key, options = nil)
17
17
  super
18
- @cache.get(key)
18
+ @cache.get(key, !(options && options[:raw]))
19
19
  end
20
20
 
21
21
  # Set the key to the given value. Pass :unless_exist => true if you want to
@@ -23,7 +23,7 @@ module ActiveSupport
23
23
  def write(key, value, options = nil)
24
24
  super
25
25
  method = unless_exist?(options) ? :add : :set
26
- @cache.send(method, key, value, expiry(options).to_i)
26
+ @cache.send(method, key, value, expiry(options).to_i, !(options && options[:raw]))
27
27
  end
28
28
 
29
29
  def delete(key, options = nil)
data/lib/spymemcached.rb CHANGED
@@ -12,12 +12,13 @@ class Spymemcached
12
12
  end)
13
13
  end
14
14
 
15
- def set(key, value, expiration = 0)
16
- @client.set(key, expiration, value)
15
+ def set(key, value, expiration = 0, marshal = true)
16
+ @client.set(key, expiration, marshal(value, marshal))
17
17
  end
18
18
 
19
- def get(key)
20
- @client.get(key)
19
+ def get(key, marshal = true)
20
+ value = @client.get(key)
21
+ marshal && value ? Marshal.load(value) : value
21
22
  end
22
23
 
23
24
  def incr(key, by = 1)
@@ -36,12 +37,12 @@ class Spymemcached
36
37
  @client.prepend(0, key, value).get
37
38
  end
38
39
 
39
- def multiget(*keys)
40
- Hash[*@client.getBulk(*keys).map { |k,v| [k,v] }.flatten]
40
+ def multiget(keys, marshal = true)
41
+ Hash[*@client.getBulk(*keys).map { |k,v| [k, marshal ? Marshal.load(v) : v] }.flatten]
41
42
  end
42
43
 
43
- def add(key, value, expiration = 0)
44
- @client.add(key, expiration, value).get
44
+ def add(key, value, expiration = 0, marshal = true)
45
+ @client.add(key, expiration, marshal(value, marshal)).get
45
46
  end
46
47
 
47
48
  def del(key)
@@ -51,4 +52,9 @@ class Spymemcached
51
52
  def flush
52
53
  @client.flush
53
54
  end
55
+
56
+ private
57
+ def marshal(value, marshal)
58
+ marshal ? Marshal.dump(value) : value.to_s
59
+ end
54
60
  end
@@ -22,48 +22,48 @@ describe Spymemcached do
22
22
  end
23
23
 
24
24
  it "increments keys" do
25
- @cache.set("number", "1")
25
+ @cache.set("number", "1", 0, false)
26
26
  @cache.incr("number")
27
- @cache.get("number").should == "2"
27
+ @cache.get("number", false).should == "2"
28
28
  end
29
29
 
30
30
  it "increments keys by a set amount" do
31
- @cache.set("number", "1")
31
+ @cache.set("number", "1", 0, false)
32
32
  @cache.incr("number", 2)
33
- @cache.get("number").should == "3"
33
+ @cache.get("number", false).should == "3"
34
34
  end
35
35
 
36
36
  it "decrements keys" do
37
- @cache.set("number", "2")
37
+ @cache.set("number", "2", 0, false)
38
38
  @cache.decr("number")
39
- @cache.get("number").should == "1"
39
+ @cache.get("number", false).should == "1"
40
40
  end
41
41
 
42
42
  it "decrements keys by a set amount" do
43
- @cache.set("number", "2")
43
+ @cache.set("number", "2", 0, false)
44
44
  @cache.decr("number", 2)
45
- @cache.get("number").should == "0"
45
+ @cache.get("number", false).should == "0"
46
46
  end
47
47
 
48
48
  it "appends to keys" do
49
- @cache.set("appendtome", "a")
49
+ @cache.set("appendtome", "a", 0, false)
50
50
  @cache.append("appendtome", "b")
51
- @cache.get("appendtome").should == "ab"
51
+ @cache.get("appendtome", false).should == "ab"
52
52
  end
53
53
 
54
54
  it "prepends to keys" do
55
- @cache.set("prependtome", "b")
55
+ @cache.set("prependtome", "b", 0, false)
56
56
  @cache.prepend("prependtome", "a")
57
- @cache.get("prependtome").should == "ab"
57
+ @cache.get("prependtome", false).should == "ab"
58
58
  end
59
59
 
60
60
  it "returns boolean for prepend" do
61
- @cache.set("prependtome", "b")
61
+ @cache.set("prependtome", "b", 0, false)
62
62
  @cache.prepend("prependtome", "a").should == true
63
63
  end
64
64
 
65
65
  it "returns boolean for append" do
66
- @cache.set("appendtome", "b")
66
+ @cache.set("appendtome", "b", 0, false)
67
67
  @cache.append("appendtome", "a").should == true
68
68
  end
69
69
 
@@ -71,7 +71,7 @@ describe Spymemcached do
71
71
  @cache.set("a", "b")
72
72
  @cache.set("b", "c")
73
73
  @cache.set("c", "d")
74
- @cache.multiget("a", "b", "c").should == {
74
+ @cache.multiget(["a", "b", "c"]).should == {
75
75
  "a" => "b",
76
76
  "b" => "c",
77
77
  "c" => "d"
@@ -100,4 +100,19 @@ describe Spymemcached do
100
100
  @cache.set("a", "b")
101
101
  @cache.del("a").should == true
102
102
  end
103
+
104
+ it "correctly marshals and unmarshals objects" do
105
+ @cache.set("a", {:a => "b"})
106
+ @cache.get("a").should == {:a => "b"}
107
+ end
108
+
109
+ it "supports setting and getting keys without marshalling the data" do
110
+ @cache.set("a", {:a => "b"}, 0, false)
111
+ @cache.get("a", false).should == {:a => "b"}.to_s
112
+ end
113
+
114
+ it "supports adding keys without marshalling the data" do
115
+ @cache.add("a", {:a => "b"}, 0, false)
116
+ @cache.get("a", false).should == {:a => "b"}.to_s
117
+ end
103
118
  end
@@ -37,27 +37,27 @@ describe "SpymemcachedStore" do
37
37
  end
38
38
 
39
39
  it "supports increment" do
40
- @cache.write("a", "1")
40
+ @cache.write("a", "1", :raw => true)
41
41
  @cache.increment("a")
42
- @cache.read("a").should == "2"
42
+ @cache.read("a", :raw => true).should == "2"
43
43
  end
44
44
 
45
45
  it "supports incrementing by a specific amount" do
46
- @cache.write("a", "1")
46
+ @cache.write("a", "1", :raw => true)
47
47
  @cache.increment("a", 2)
48
- @cache.read("a").should == "3"
48
+ @cache.read("a", :raw => true).should == "3"
49
49
  end
50
50
 
51
51
  it "supports decrement" do
52
- @cache.write("a", "1")
52
+ @cache.write("a", "1", :raw => true)
53
53
  @cache.decrement("a")
54
- @cache.read("a").should == "0"
54
+ @cache.read("a", :raw => true).should == "0"
55
55
  end
56
56
 
57
57
  it "supports decrementing by a specific amount" do
58
- @cache.write("a", "2")
58
+ @cache.write("a", "2", :raw => true)
59
59
  @cache.decrement("a", 2)
60
- @cache.read("a").should == "0"
60
+ @cache.read("a", :raw => true).should == "0"
61
61
  end
62
62
 
63
63
  it "supports :expires_in with a duration argument" do
data/spymemcached.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{spymemcached}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
  s.platform = %q{java}
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
7
  - 2
9
- version: 0.1.2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: java
11
11
  authors:
12
12
  - James Golick