fakeredis 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -2,8 +2,4 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'fakeredis'
5
- require "fakeredis/rspec"
6
5
 
7
- def fakeredis?
8
- true
9
- end
data/spec/strings_spec.rb CHANGED
@@ -11,121 +11,89 @@ module FakeRedis
11
11
  @client.set("key1", "Hello")
12
12
  @client.append("key1", " World")
13
13
 
14
- @client.get("key1").should be == "Hello World"
14
+ @client.get("key1").should == "Hello World"
15
15
  end
16
16
 
17
17
  it "should decrement the integer value of a key by one" do
18
18
  @client.set("counter", "1")
19
19
  @client.decr("counter")
20
20
 
21
- @client.get("counter").should be == "0"
21
+ @client.get("counter").should == "0"
22
22
  end
23
23
 
24
24
  it "should decrement the integer value of a key by the given number" do
25
25
  @client.set("counter", "10")
26
26
  @client.decrby("counter", "5")
27
27
 
28
- @client.get("counter").should be == "5"
28
+ @client.get("counter").should == "5"
29
29
  end
30
30
 
31
31
  it "should get the value of a key" do
32
- @client.get("key2").should be == nil
32
+ @client.get("key2").should == nil
33
33
  end
34
34
 
35
35
  it "should returns the bit value at offset in the string value stored at key" do
36
36
  @client.set("key1", "a")
37
37
 
38
- @client.getbit("key1", 1).should be == 1
39
- @client.getbit("key1", 2).should be == 1
40
- @client.getbit("key1", 3).should be == 0
41
- @client.getbit("key1", 4).should be == 0
42
- @client.getbit("key1", 5).should be == 0
43
- @client.getbit("key1", 6).should be == 0
44
- @client.getbit("key1", 7).should be == 1
38
+ @client.getbit("key1", 1).should == 1
39
+ @client.getbit("key1", 2).should == 1
40
+ @client.getbit("key1", 3).should == 0
41
+ @client.getbit("key1", 4).should == 0
42
+ @client.getbit("key1", 5).should == 0
43
+ @client.getbit("key1", 6).should == 0
44
+ @client.getbit("key1", 7).should == 1
45
45
  end
46
46
 
47
47
  it "should allow direct bit manipulation even if the string isn't set" do
48
48
  @client.setbit("key1", 10, 1)
49
- @client.getbit("key1", 10).should be == 1
49
+ @client.getbit("key1", 10).should == 1
50
50
  end
51
51
 
52
52
  it "should get a substring of the string stored at a key" do
53
53
  @client.set("key1", "This a message")
54
54
 
55
- @client.getrange("key1", 0, 3).should be == "This"
56
- @client.substr("key1", 0, 3).should be == "This"
55
+ @client.getrange("key1", 0, 3).should == "This"
56
+ @client.substr("key1", 0, 3).should == "This"
57
57
  end
58
58
 
59
59
  it "should set the string value of a key and return its old value" do
60
60
  @client.set("key1","value1")
61
61
 
62
- @client.getset("key1", "value2").should be == "value1"
63
- @client.get("key1").should be == "value2"
62
+ @client.getset("key1", "value2").should == "value1"
63
+ @client.get("key1").should == "value2"
64
64
  end
65
65
 
66
66
  it "should return nil for #getset if the key does not exist when setting" do
67
- @client.getset("key1", "value1").should be_nil
68
- @client.get("key1").should be == "value1"
67
+ @client.getset("key1", "value1").should == nil
68
+ @client.get("key1").should == "value1"
69
69
  end
70
70
 
71
71
  it "should increment the integer value of a key by one" do
72
72
  @client.set("counter", "1")
73
- @client.incr("counter").should be == 2
73
+ @client.incr("counter").should == 2
74
74
 
75
- @client.get("counter").should be == "2"
76
- end
77
-
78
- it "should not change the expire value of the key during incr" do
79
- @client.set("counter", "1")
80
- @client.expire("counter", 600).should be_true
81
- @client.ttl("counter").should be == 600
82
- @client.incr("counter").should be == 2
83
- @client.ttl("counter").should be == 600
75
+ @client.get("counter").should == "2"
84
76
  end
85
77
 
86
78
  it "should decrement the integer value of a key by one" do
87
79
  @client.set("counter", "1")
88
- @client.decr("counter").should be == 0
89
-
90
- @client.get("counter").should be == "0"
91
- end
80
+ @client.decr("counter").should == 0
92
81
 
93
- it "should not change the expire value of the key during decr" do
94
- @client.set("counter", "2")
95
- @client.expire("counter", 600).should be_true
96
- @client.ttl("counter").should be == 600
97
- @client.decr("counter").should be == 1
98
- @client.ttl("counter").should be == 600
82
+ @client.get("counter").should == "0"
99
83
  end
100
84
 
101
85
  it "should increment the integer value of a key by the given number" do
102
86
  @client.set("counter", "10")
103
- @client.incrby("counter", "5").should be == 15
104
- @client.incrby("counter", 2).should be == 17
105
- @client.get("counter").should be == "17"
106
- end
107
-
108
- it "should not change the expire value of the key during incrby" do
109
- @client.set("counter", "1")
110
- @client.expire("counter", 600).should be_true
111
- @client.ttl("counter").should be == 600
112
- @client.incrby("counter", "5").should be == 6
113
- @client.ttl("counter").should be == 600
87
+ @client.incrby("counter", "5").should == 15
88
+ @client.incrby("counter", 2).should == 17
89
+ @client.get("counter").should == "17"
114
90
  end
115
91
 
116
92
  it "should decrement the integer value of a key by the given number" do
117
93
  @client.set("counter", "10")
118
- @client.decrby("counter", "5").should be == 5
119
- @client.decrby("counter", 2).should be == 3
120
- @client.get("counter").should be == "3"
121
- end
122
-
123
- it "should not change the expire value of the key during decrby" do
124
- @client.set("counter", "8")
125
- @client.expire("counter", 600).should be_true
126
- @client.ttl("counter").should be == 600
127
- @client.decrby("counter", "3").should be == 5
128
- @client.ttl("counter").should be == 600
94
+ @client.decrby("counter", "5").should == 5
95
+ @client.decrby("counter", 2).should == 3
96
+ @client.get("counter").should == "3"
129
97
  end
130
98
 
131
99
  it "should get the values of all the given keys" do
@@ -133,63 +101,48 @@ module FakeRedis
133
101
  @client.set("key2", "value2")
134
102
  @client.set("key3", "value3")
135
103
 
136
- @client.mget("key1", "key2", "key3").should be == ["value1", "value2", "value3"]
104
+ @client.mget("key1", "key2", "key3").should == ["value1", "value2", "value3"]
137
105
  end
138
106
 
139
- it "raises an argument error when not passed any fields" do
107
+ it 'raises an argument error when not passed any fields' do
140
108
  @client.set("key3", "value3")
141
109
 
142
- lambda { @client.mget }.should raise_error(RuntimeError, "ERR wrong number of arguments for 'mget' command")
110
+ lambda { @client.mget }.should raise_error(ArgumentError)
143
111
  end
144
112
 
145
113
  it "should set multiple keys to multiple values" do
146
114
  @client.mset(:key1, "value1", :key2, "value2")
147
115
 
148
- @client.get("key1").should be == "value1"
149
- @client.get("key2").should be == "value2"
116
+ @client.get("key1").should == "value1"
117
+ @client.get("key2").should == "value2"
150
118
  end
151
119
 
152
120
  it "should set multiple keys to multiple values, only if none of the keys exist" do
153
- @client.msetnx(:key1, "value1", :key2, "value2").should be == 1
154
- @client.msetnx(:key1, "value3", :key2, "value4").should be == 0
155
-
156
- @client.get("key1").should be == "value1"
157
- @client.get("key2").should be == "value2"
158
- end
159
-
160
- it "should set multiple keys to multiple values with a hash" do
161
- @client.mapped_mset(:key1 => "value1", :key2 => "value2")
162
-
163
- @client.get("key1").should be == "value1"
164
- @client.get("key2").should be == "value2"
165
- end
166
-
167
- it "should set multiple keys to multiple values with a hash, only if none of the keys exist" do
168
- @client.mapped_msetnx(:key1 => "value1", :key2 => "value2").should be == 1
169
- @client.mapped_msetnx(:key1 => "value3", :key2 => "value4").should be == 0
121
+ @client.msetnx(:key1, "value1", :key2, "value2")
122
+ @client.msetnx(:key1, "value3", :key2, "value4")
170
123
 
171
- @client.get("key1").should be == "value1"
172
- @client.get("key2").should be == "value2"
124
+ @client.get("key1").should == "value1"
125
+ @client.get("key2").should == "value2"
173
126
  end
174
127
 
175
128
  it "should set the string value of a key" do
176
129
  @client.set("key1", "1")
177
130
 
178
- @client.get("key1").should be == "1"
131
+ @client.get("key1").should == "1"
179
132
  end
180
133
 
181
134
  it "should sets or clears the bit at offset in the string value stored at key" do
182
135
  @client.set("key1", "abc")
183
136
  @client.setbit("key1", 11, 1)
184
137
 
185
- @client.get("key1").should be == "arc"
138
+ @client.get("key1").should == "arc"
186
139
  end
187
140
 
188
141
  it "should set the value and expiration of a key" do
189
142
  @client.setex("key1", 30, "value1")
190
143
 
191
- @client.get("key1").should be == "value1"
192
- @client.ttl("key1").should be == 30
144
+ @client.get("key1").should == "value1"
145
+ @client.ttl("key1").should == 30
193
146
  end
194
147
 
195
148
  it "should set the value of a key, only if the key does not exist" do
@@ -197,21 +150,21 @@ module FakeRedis
197
150
  @client.setnx("key1", "new value")
198
151
  @client.setnx("key2", "another value")
199
152
 
200
- @client.get("key1").should be == "test value"
201
- @client.get("key2").should be == "another value"
153
+ @client.get("key1").should == "test value"
154
+ @client.get("key2").should == "another value"
202
155
  end
203
156
 
204
157
  it "should overwrite part of a string at key starting at the specified offset" do
205
158
  @client.set("key1", "Hello World")
206
159
  @client.setrange("key1", 6, "Redis")
207
160
 
208
- @client.get("key1").should be == "Hello Redis"
161
+ @client.get("key1").should == "Hello Redis"
209
162
  end
210
163
 
211
164
  it "should get the length of the value stored in a key" do
212
165
  @client.set("key1", "abc")
213
166
 
214
- @client.strlen("key1").should be == 3
167
+ @client.strlen("key1").should == 3
215
168
  end
216
169
 
217
170
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakeredis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
12
+ date: 2012-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.2.0
21
+ version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 2.2.0
29
+ version: 3.0.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -59,14 +59,9 @@ files:
59
59
  - README.md
60
60
  - Rakefile
61
61
  - fakeredis.gemspec
62
- - lib/fake_redis.rb
63
62
  - lib/fakeredis.rb
64
- - lib/fakeredis/expiring_hash.rb
65
63
  - lib/fakeredis/rspec.rb
66
- - lib/fakeredis/sorted_set_argument_handler.rb
67
- - lib/fakeredis/sorted_set_store.rb
68
64
  - lib/fakeredis/version.rb
69
- - lib/fakeredis/zset.rb
70
65
  - lib/redis/connection/memory.rb
71
66
  - spec/compatibility_spec.rb
72
67
  - spec/connection_spec.rb
@@ -77,12 +72,10 @@ files:
77
72
  - spec/sets_spec.rb
78
73
  - spec/sorted_sets_spec.rb
79
74
  - spec/spec_helper.rb
80
- - spec/spec_helper_live_redis.rb
81
75
  - spec/strings_spec.rb
82
76
  - spec/transactions_spec.rb
83
- homepage: https://guilleiguaran.github.com/fakeredis
84
- licenses:
85
- - MIT
77
+ homepage: https://github.com/guilleiguaran/fakeredis
78
+ licenses: []
86
79
  post_install_message:
87
80
  rdoc_options: []
88
81
  require_paths:
@@ -100,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
93
  - !ruby/object:Gem::Version
101
94
  version: '0'
102
95
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 1.8.23
96
+ rubyforge_project: fakeredis
97
+ rubygems_version: 1.8.24
105
98
  signing_key:
106
99
  specification_version: 3
107
100
  summary: Fake (In-memory) driver for redis-rb.
@@ -115,6 +108,6 @@ test_files:
115
108
  - spec/sets_spec.rb
116
109
  - spec/sorted_sets_spec.rb
117
110
  - spec/spec_helper.rb
118
- - spec/spec_helper_live_redis.rb
119
111
  - spec/strings_spec.rb
120
112
  - spec/transactions_spec.rb
113
+ has_rdoc:
data/lib/fake_redis.rb DELETED
@@ -1 +0,0 @@
1
- require "fakeredis"
@@ -1,56 +0,0 @@
1
- module FakeRedis
2
- # Represents a normal hash with some additional expiration information
3
- # associated with each key
4
- class ExpiringHash < Hash
5
- attr_reader :expires
6
-
7
- def initialize(*)
8
- super
9
- @expires = {}
10
- end
11
-
12
- def [](key)
13
- delete(key) if expired?(key)
14
- super
15
- end
16
-
17
- def []=(key, val)
18
- expire(key)
19
- super
20
- end
21
-
22
- def delete(key)
23
- expire(key)
24
- super
25
- end
26
-
27
- def expire(key)
28
- expires.delete(key)
29
- end
30
-
31
- def expired?(key)
32
- expires.include?(key) && expires[key] < Time.now
33
- end
34
-
35
- def key?(key)
36
- delete(key) if expired?(key)
37
- super
38
- end
39
-
40
- def values_at(*keys)
41
- keys.each {|key| delete(key) if expired?(key)}
42
- super
43
- end
44
-
45
- def keys
46
- super.select do |key|
47
- if expired?(key)
48
- delete(key)
49
- false
50
- else
51
- true
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,74 +0,0 @@
1
- module FakeRedis
2
- # Takes in the variable length array of arguments for a zinterstore/zunionstore method
3
- # and parses them into a few attributes for the method to access.
4
- #
5
- # Handles throwing errors for various scenarios (matches redis):
6
- # * Custom weights specified, but not enough or too many given
7
- # * Invalid aggregate value given
8
- # * Multiple aggregate values given
9
- class SortedSetArgumentHandler
10
- # [Symbol] The aggregate method to use for the output values. One of %w(sum min max) expected
11
- attr_reader :aggregate
12
- # [Integer] Number of keys in the argument list
13
- attr_accessor :number_of_keys
14
- # [Array] The actual keys in the argument list
15
- attr_accessor :keys
16
- # [Array] integers for weighting the values of each key - one number per key expected
17
- attr_accessor :weights
18
-
19
- # Used internally
20
- attr_accessor :type
21
-
22
- # Expects all the argments for the method to be passed as an array
23
- def initialize args
24
- # Pull out known lengths of data
25
- self.number_of_keys = args.shift
26
- self.keys = args.shift(number_of_keys)
27
- # Handle the variable lengths of data (WEIGHTS/AGGREGATE)
28
- args.inject(self) {|handler, item| handler.handle(item) }
29
-
30
- # Defaults for unspecified things
31
- self.weights ||= Array.new(number_of_keys) { 1 }
32
- self.aggregate ||= :sum
33
-
34
- # Validate values
35
- raise(RuntimeError, "ERR syntax error") unless weights.size == number_of_keys
36
- raise(RuntimeError, "ERR syntax error") unless [:min, :max, :sum].include?(aggregate)
37
- end
38
-
39
- # Only allows assigning a value *once* - raises Redis::CommandError if a second is given
40
- def aggregate=(str)
41
- raise(RuntimeError, "ERR syntax error") if (defined?(@aggregate) && @aggregate)
42
- @aggregate = str.to_s.downcase.to_sym
43
- end
44
-
45
- # Decides how to handle an item, depending on where we are in the arguments
46
- def handle(item)
47
- case item
48
- when "WEIGHTS"
49
- self.type = :weights
50
- self.weights = []
51
- when "AGGREGATE"
52
- self.type = :aggregate
53
- when nil
54
- # This should never be called, raise a syntax error if we manage to hit it
55
- raise(RuntimeError, "ERR syntax error")
56
- else
57
- send "handle_#{type}", item
58
- end
59
- self
60
- end
61
-
62
- def handle_weights(item)
63
- self.weights << item
64
- end
65
-
66
- def handle_aggregate(item)
67
- self.aggregate = item
68
- end
69
-
70
- def inject_block
71
- lambda { |handler, item| handler.handle(item) }
72
- end
73
- end
74
- end