kuende-fakeredis 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +19 -0
  4. data/Gemfile +13 -0
  5. data/Guardfile +8 -0
  6. data/LICENSE +21 -0
  7. data/README.md +102 -0
  8. data/Rakefile +27 -0
  9. data/fakeredis.gemspec +24 -0
  10. data/gemfiles/redisrb-master.gemfile +14 -0
  11. data/lib/fake_redis.rb +1 -0
  12. data/lib/fakeredis.rb +6 -0
  13. data/lib/fakeredis/bitop_command.rb +56 -0
  14. data/lib/fakeredis/command_executor.rb +25 -0
  15. data/lib/fakeredis/expiring_hash.rb +70 -0
  16. data/lib/fakeredis/minitest.rb +24 -0
  17. data/lib/fakeredis/rspec.rb +24 -0
  18. data/lib/fakeredis/sort_method.rb +117 -0
  19. data/lib/fakeredis/sorted_set_argument_handler.rb +74 -0
  20. data/lib/fakeredis/sorted_set_store.rb +80 -0
  21. data/lib/fakeredis/transaction_commands.rb +83 -0
  22. data/lib/fakeredis/version.rb +3 -0
  23. data/lib/fakeredis/zset.rb +39 -0
  24. data/lib/redis/connection/memory.rb +1375 -0
  25. data/spec/bitop_command_spec.rb +209 -0
  26. data/spec/compatibility_spec.rb +9 -0
  27. data/spec/connection_spec.rb +85 -0
  28. data/spec/hashes_spec.rb +261 -0
  29. data/spec/keys_spec.rb +488 -0
  30. data/spec/lists_spec.rb +229 -0
  31. data/spec/memory_spec.rb +28 -0
  32. data/spec/server_spec.rb +100 -0
  33. data/spec/sets_spec.rb +280 -0
  34. data/spec/sort_method_spec.rb +74 -0
  35. data/spec/sorted_sets_spec.rb +578 -0
  36. data/spec/spec_helper.rb +29 -0
  37. data/spec/spec_helper_live_redis.rb +14 -0
  38. data/spec/strings_spec.rb +289 -0
  39. data/spec/subscription_spec.rb +107 -0
  40. data/spec/support/shared_examples/bitwise_operation.rb +59 -0
  41. data/spec/support/shared_examples/sortable.rb +69 -0
  42. data/spec/transactions_spec.rb +92 -0
  43. data/spec/upcase_method_name_spec.rb +18 -0
  44. metadata +148 -0
@@ -0,0 +1,209 @@
1
+ require 'spec_helper'
2
+
3
+ module FakeRedis
4
+ describe "#bitop" do
5
+ before(:all) do
6
+ @client = Redis.new
7
+ end
8
+
9
+ before(:each) do
10
+ @client.discard rescue nil
11
+ end
12
+
13
+ it 'raises an argument error when passed unsupported operation' do
14
+ lambda { @client.bitop("meh", "dest1", "key1") }.should raise_error(Redis::CommandError)
15
+ end
16
+
17
+ describe "or" do
18
+ it_should_behave_like "a bitwise operation", "or"
19
+
20
+ it "should apply bitwise or operation" do
21
+ @client.setbit("key1", 0, 0)
22
+ @client.setbit("key1", 1, 1)
23
+ @client.setbit("key1", 2, 1)
24
+ @client.setbit("key1", 3, 0)
25
+
26
+ @client.setbit("key2", 0, 1)
27
+ @client.setbit("key2", 1, 1)
28
+ @client.setbit("key2", 2, 0)
29
+ @client.setbit("key2", 3, 0)
30
+
31
+ @client.bitop("or", "dest1", "key1", "key2").should be == 1
32
+ @client.bitcount("dest1").should be == 3
33
+ @client.getbit("dest1", 0).should be == 1
34
+ @client.getbit("dest1", 1).should be == 1
35
+ @client.getbit("dest1", 2).should be == 1
36
+ @client.getbit("dest1", 3).should be == 0
37
+ end
38
+
39
+ it "should apply bitwise or operation with empty values" do
40
+ @client.setbit("key1", 1, 1)
41
+
42
+ @client.bitop("or", "dest1", "key1", "nothing_here1", "nothing_here2").should be == 1
43
+ @client.bitcount("dest1").should be == 1
44
+ @client.getbit("dest1", 0).should be == 0
45
+ @client.getbit("dest1", 1).should be == 1
46
+ @client.getbit("dest1", 2).should be == 0
47
+ end
48
+
49
+ it "should apply bitwise or operation with multiple keys" do
50
+ @client.setbit("key1", 1, 1)
51
+ @client.setbit("key1", 3, 1)
52
+
53
+ @client.setbit("key2", 5, 1)
54
+ @client.setbit("key2", 10, 1)
55
+
56
+ @client.setbit("key3", 13, 1)
57
+ @client.setbit("key3", 15, 1)
58
+
59
+ @client.bitop("or", "dest1", "key1", "key2", "key3").should be == 2
60
+ @client.bitcount("dest1").should be == 6
61
+ @client.getbit("dest1", 1).should be == 1
62
+ @client.getbit("dest1", 3).should be == 1
63
+ @client.getbit("dest1", 5).should be == 1
64
+ @client.getbit("dest1", 10).should be == 1
65
+ @client.getbit("dest1", 13).should be == 1
66
+ @client.getbit("dest1", 15).should be == 1
67
+ @client.getbit("dest1", 2).should be == 0
68
+ @client.getbit("dest1", 12).should be == 0
69
+ end
70
+ end
71
+
72
+ describe "and" do
73
+ it_should_behave_like "a bitwise operation", "and"
74
+
75
+ it "should apply bitwise and operation" do
76
+ @client.setbit("key1", 0, 1)
77
+ @client.setbit("key1", 1, 1)
78
+ @client.setbit("key1", 2, 0)
79
+
80
+ @client.setbit("key2", 0, 0)
81
+ @client.setbit("key2", 1, 1)
82
+ @client.setbit("key2", 2, 1)
83
+
84
+ @client.bitop("and", "dest1", "key1", "key2").should be == 1
85
+ @client.bitcount("dest1").should be == 1
86
+ @client.getbit("dest1", 0).should be == 0
87
+ @client.getbit("dest1", 1).should be == 1
88
+ @client.getbit("dest1", 2).should be == 0
89
+ end
90
+
91
+ it "should apply bitwise and operation with empty values" do
92
+ @client.setbit("key1", 1, 1)
93
+
94
+ @client.bitop("and", "dest1", "key1", "nothing_here").should be == 1
95
+ @client.bitcount("dest1").should be == 1
96
+ @client.getbit("dest1", 0).should be == 0
97
+ @client.getbit("dest1", 1).should be == 1
98
+ @client.getbit("dest1", 2).should be == 0
99
+ end
100
+
101
+ it "should apply bitwise and operation with multiple keys" do
102
+ @client.setbit("key1", 1, 1)
103
+ @client.setbit("key1", 2, 1)
104
+ @client.setbit("key1", 3, 1)
105
+ @client.setbit("key1", 4, 1)
106
+
107
+ @client.setbit("key2", 2, 1)
108
+ @client.setbit("key2", 3, 1)
109
+ @client.setbit("key2", 4, 1)
110
+ @client.setbit("key2", 5, 1)
111
+
112
+ @client.setbit("key3", 2, 1)
113
+ @client.setbit("key3", 4, 1)
114
+ @client.setbit("key3", 5, 1)
115
+ @client.setbit("key3", 6, 1)
116
+
117
+ @client.bitop("and", "dest1", "key1", "key2", "key3").should be == 1
118
+ @client.bitcount("dest1").should be == 2
119
+ @client.getbit("dest1", 1).should be == 0
120
+ @client.getbit("dest1", 2).should be == 1
121
+ @client.getbit("dest1", 3).should be == 0
122
+ @client.getbit("dest1", 4).should be == 1
123
+ @client.getbit("dest1", 5).should be == 0
124
+ @client.getbit("dest1", 6).should be == 0
125
+ end
126
+ end
127
+
128
+ describe "xor" do
129
+ it_should_behave_like "a bitwise operation", "xor"
130
+
131
+ it "should apply bitwise xor operation" do
132
+ @client.setbit("key1", 0, 0)
133
+ @client.setbit("key1", 1, 1)
134
+ @client.setbit("key1", 2, 0)
135
+ @client.setbit("key1", 3, 0)
136
+
137
+ @client.setbit("key2", 0, 1)
138
+ @client.setbit("key2", 1, 1)
139
+ @client.setbit("key2", 2, 1)
140
+ @client.setbit("key2", 3, 0)
141
+
142
+ @client.bitop("xor", "dest1", "key1", "key2").should be == 1
143
+ @client.bitcount("dest1").should be == 2
144
+ @client.getbit("dest1", 0).should be == 1
145
+ @client.getbit("dest1", 1).should be == 0
146
+ @client.getbit("dest1", 2).should be == 1
147
+ @client.getbit("dest1", 3).should be == 0
148
+ end
149
+
150
+ it "should apply bitwise xor operation with empty values" do
151
+ @client.setbit("key1", 1, 1)
152
+
153
+ @client.bitop("xor", "dest1", "key1", "nothing_here1", "nothing_here2").should be == 1
154
+ @client.bitcount("dest1").should be == 1
155
+ @client.getbit("dest1", 0).should be == 0
156
+ @client.getbit("dest1", 1).should be == 1
157
+ @client.getbit("dest1", 2).should be == 0
158
+ end
159
+
160
+ it "should apply bitwise xor operation with multiple keys" do
161
+ @client.setbit("key1", 1, 1)
162
+ @client.setbit("key1", 3, 1)
163
+ @client.setbit("key1", 5, 1)
164
+ @client.setbit("key1", 6, 1)
165
+
166
+ @client.setbit("key2", 2, 1)
167
+ @client.setbit("key2", 3, 1)
168
+ @client.setbit("key2", 4, 1)
169
+ @client.setbit("key2", 6, 1)
170
+
171
+ @client.bitop("xor", "dest1", "key1", "key2").should be == 1
172
+ @client.bitcount("dest1").should be == 4
173
+ @client.getbit("dest1", 1).should be == 1
174
+ @client.getbit("dest1", 2).should be == 1
175
+ @client.getbit("dest1", 3).should be == 0
176
+ @client.getbit("dest1", 4).should be == 1
177
+ @client.getbit("dest1", 5).should be == 1
178
+ @client.getbit("dest1", 6).should be == 0
179
+ end
180
+ end
181
+
182
+ describe "not" do
183
+ it 'raises an argument error when not passed any keys' do
184
+ lambda { @client.bitop("not", "destkey") }.should raise_error(Redis::CommandError)
185
+ end
186
+
187
+ it 'raises an argument error when not passed too many keys' do
188
+ lambda { @client.bitop("not", "destkey", "key1", "key2") }.should raise_error(Redis::CommandError)
189
+ end
190
+
191
+ it "should apply bitwise negation operation" do
192
+ @client.setbit("key1", 1, 1)
193
+ @client.setbit("key1", 3, 1)
194
+ @client.setbit("key1", 5, 1)
195
+
196
+ @client.bitop("not", "dest1", "key1").should be == 1
197
+ @client.bitcount("dest1").should be == 5
198
+ @client.getbit("dest1", 0).should be == 1
199
+ @client.getbit("dest1", 1).should be == 0
200
+ @client.getbit("dest1", 2).should be == 1
201
+ @client.getbit("dest1", 3).should be == 0
202
+ @client.getbit("dest1", 4).should be == 1
203
+ @client.getbit("dest1", 5).should be == 0
204
+ @client.getbit("dest1", 6).should be == 1
205
+ @client.getbit("dest1", 7).should be == 1
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module FakeRedis
4
+ describe "Compatibility" do
5
+ it "should be accessible through FakeRedis::Redis" do
6
+ expect { FakeRedis::Redis.new }.not_to raise_error
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ module FakeRedis
4
+ describe "ConnectionMethods" do
5
+
6
+ before(:each) do
7
+ @client = Redis.new
8
+ end
9
+
10
+ if fakeredis?
11
+ it "should authenticate to the server" do
12
+ expect(@client.auth("pass")).to eq("OK")
13
+ end
14
+
15
+ it "should re-use the same instance with the same host & port" do
16
+ @client1 = Redis.new(:host => "localhost", :port => 1234)
17
+ @client2 = Redis.new(:host => "localhost", :port => 1234)
18
+ @client3 = Redis.new(:host => "localhost", :port => 5678)
19
+
20
+ @client1.set("key1", "1")
21
+ expect(@client2.get("key1")).to eq("1")
22
+ expect(@client3.get("key1")).to be_nil
23
+
24
+ @client2.set("key2", "2")
25
+ expect(@client1.get("key2")).to eq("2")
26
+ expect(@client3.get("key2")).to be_nil
27
+
28
+ @client3.set("key3", "3")
29
+ expect(@client1.get("key3")).to be_nil
30
+ expect(@client2.get("key3")).to be_nil
31
+
32
+ expect(@client1.dbsize).to eq(2)
33
+ expect(@client2.dbsize).to eq(2)
34
+ expect(@client3.dbsize).to eq(1)
35
+ end
36
+
37
+ it "should connect to a specific database" do
38
+ @client1 = Redis.new(:host => "localhost", :port => 1234, :db => 0)
39
+ @client1.set("key1", "1")
40
+ @client1.select(0)
41
+ expect(@client1.get("key1")).to eq("1")
42
+
43
+ @client2 = Redis.new(:host => "localhost", :port => 1234, :db => 1)
44
+ @client2.set("key1", "1")
45
+ @client2.select(1)
46
+ expect(@client2.get("key1")).to eq("1")
47
+ end
48
+
49
+ it "should not error with shutdown" do
50
+ expect { @client.shutdown }.not_to raise_error
51
+ end
52
+
53
+ it "should not error with quit" do
54
+ expect { @client.quit }.not_to raise_error
55
+ end
56
+ end
57
+
58
+ it "should handle multiple clients using the same db instance" do
59
+ @client1 = Redis.new(:host => "localhost", :port => 6379, :db => 1)
60
+ @client2 = Redis.new(:host => "localhost", :port => 6379, :db => 2)
61
+
62
+ @client1.set("key1", "one")
63
+ expect(@client1.get("key1")).to eq("one")
64
+
65
+ @client2.set("key2", "two")
66
+ expect(@client2.get("key2")).to eq("two")
67
+
68
+ expect(@client1.get("key1")).to eq("one")
69
+ end
70
+
71
+ it "should not error with a disconnected client" do
72
+ @client1 = Redis.new
73
+ @client1.client.disconnect
74
+ expect(@client1.get("key1")).to be_nil
75
+ end
76
+
77
+ it "should echo the given string" do
78
+ expect(@client.echo("something")).to eq("something")
79
+ end
80
+
81
+ it "should ping the server" do
82
+ expect(@client.ping).to eq("PONG")
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,261 @@
1
+ require 'spec_helper'
2
+
3
+ module FakeRedis
4
+ describe "HashesMethods" do
5
+ before(:each) do
6
+ @client = Redis.new
7
+ end
8
+
9
+ it "should delete a hash field" do
10
+ @client.hset("key1", "k1", "val1")
11
+ @client.hset("key1", "k2", "val2")
12
+ expect(@client.hdel("key1", "k1")).to be(1)
13
+
14
+ expect(@client.hget("key1", "k1")).to be_nil
15
+ expect(@client.hget("key1", "k2")).to eq("val2")
16
+ end
17
+
18
+ it "should delete array of fields" do
19
+ @client.hset("key1", "k1", "val1")
20
+ @client.hset("key1", "k2", "val2")
21
+ @client.hset("key1", "k3", "val3")
22
+ expect(@client.hdel("key1", ["k1", "k2"])).to be(2)
23
+
24
+ expect(@client.hget("key1", "k1")).to be_nil
25
+ expect(@client.hget("key1", "k2")).to be_nil
26
+ expect(@client.hget("key1", "k3")).to eq("val3")
27
+ end
28
+
29
+ it "should remove a hash with no keys left" do
30
+ @client.hset("key1", "k1", "val1")
31
+ @client.hset("key1", "k2", "val2")
32
+ expect(@client.hdel("key1", "k1")).to be(1)
33
+ expect(@client.hdel("key1", "k2")).to be(1)
34
+
35
+ expect(@client.exists("key1")).to eq(false)
36
+ end
37
+
38
+ it "should convert key to a string for hset" do
39
+ m = double("key")
40
+ allow(m).to receive(:to_s).and_return("foo")
41
+
42
+ @client.hset("key1", m, "bar")
43
+ expect(@client.hget("key1", "foo")).to eq("bar")
44
+ end
45
+
46
+ it "should convert key to a string for hget" do
47
+ m = double("key")
48
+ allow(m).to receive(:to_s).and_return("foo")
49
+
50
+ @client.hset("key1", "foo", "bar")
51
+ expect(@client.hget("key1", m)).to eq("bar")
52
+ end
53
+
54
+ it "should determine if a hash field exists" do
55
+ @client.hset("key1", "index", "value")
56
+
57
+ expect(@client.hexists("key1", "index")).to be true
58
+ expect(@client.hexists("key2", "i2")).to be false
59
+ end
60
+
61
+ it "should get the value of a hash field" do
62
+ @client.hset("key1", "index", "value")
63
+
64
+ expect(@client.hget("key1", "index")).to eq("value")
65
+ end
66
+
67
+ it "should get all the fields and values in a hash" do
68
+ @client.hset("key1", "i1", "val1")
69
+ @client.hset("key1", "i2", "val2")
70
+
71
+ expect(@client.hgetall("key1")).to eq({"i1" => "val1", "i2" => "val2"})
72
+ end
73
+
74
+ it "should increment the integer value of a hash field by the given number" do
75
+ @client.hset("key1", "cont1", "5")
76
+ expect(@client.hincrby("key1", "cont1", "5")).to eq(10)
77
+ expect(@client.hget("key1", "cont1")).to eq("10")
78
+ end
79
+
80
+ it "should increment non existing hash keys" do
81
+ expect(@client.hget("key1", "cont2")).to be_nil
82
+ expect(@client.hincrby("key1", "cont2", "5")).to eq(5)
83
+ end
84
+
85
+ it "should increment the float value of a hash field by the given float" do
86
+ @client.hset("key1", "cont1", 5.0)
87
+ expect(@client.hincrbyfloat("key1", "cont1", 4.1)).to eq(9.1)
88
+ expect(@client.hget("key1", "cont1")).to eq("9.1")
89
+ end
90
+
91
+ it "should increment non existing hash keys" do
92
+ expect(@client.hget("key1", "cont2")).to be_nil
93
+ expect(@client.hincrbyfloat("key1", "cont2", 5.5)).to eq(5.5)
94
+ end
95
+
96
+ it "should get all the fields in a hash" do
97
+ @client.hset("key1", "i1", "val1")
98
+ @client.hset("key1", "i2", "val2")
99
+
100
+ expect(@client.hkeys("key1")).to match_array(["i1", "i2"])
101
+ expect(@client.hkeys("key2")).to eq([])
102
+ end
103
+
104
+ it "should get the number of fields in a hash" do
105
+ @client.hset("key1", "i1", "val1")
106
+ @client.hset("key1", "i2", "val2")
107
+
108
+ expect(@client.hlen("key1")).to eq(2)
109
+ end
110
+
111
+ it "should get the values of all the given hash fields" do
112
+ @client.hset("key1", "i1", "val1")
113
+ @client.hset("key1", "i2", "val2")
114
+
115
+ expect(@client.hmget("key1", "i1", "i2", "i3")).to match_array(["val1", "val2", nil])
116
+ expect(@client.hmget("key1", ["i1", "i2", "i3"])).to match_array(["val1", "val2", nil])
117
+
118
+ expect(@client.hmget("key2", "i1", "i2")).to eq([nil, nil])
119
+ end
120
+
121
+ it "should throw an argument error when you don't ask for any keys" do
122
+ expect { @client.hmget("key1") }.to raise_error(Redis::CommandError)
123
+ end
124
+
125
+ it "should reject an empty list of values" do
126
+ expect { @client.hmset("key") }.to raise_error(Redis::CommandError)
127
+ expect(@client.exists("key")).to be false
128
+ end
129
+
130
+ it "rejects an insert with a key but no value" do
131
+ expect { @client.hmset("key", 'foo') }.to raise_error(Redis::CommandError)
132
+ expect { @client.hmset("key", 'foo', 3, 'bar') }.to raise_error(Redis::CommandError)
133
+ expect(@client.exists("key")).to be false
134
+ end
135
+
136
+ it "should reject the wrong number of arguments" do
137
+ expect { @client.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3") }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for HMSET")
138
+ end
139
+
140
+ it "should set multiple hash fields to multiple values" do
141
+ @client.hmset("key", "k1", "value1", "k2", "value2")
142
+
143
+ expect(@client.hget("key", "k1")).to eq("value1")
144
+ expect(@client.hget("key", "k2")).to eq("value2")
145
+ end
146
+
147
+ it "should set multiple hash fields from a ruby hash to multiple values" do
148
+ @client.mapped_hmset("foo", :k1 => "value1", :k2 => "value2")
149
+
150
+ expect(@client.hget("foo", "k1")).to eq("value1")
151
+ expect(@client.hget("foo", "k2")).to eq("value2")
152
+ end
153
+
154
+ it "should set the string value of a hash field" do
155
+ expect(@client.hset("key1", "k1", "val1")).to eq(true)
156
+ expect(@client.hset("key1", "k1", "val1")).to eq(false)
157
+
158
+ expect(@client.hget("key1", "k1")).to eq("val1")
159
+ end
160
+
161
+ it "should set the value of a hash field, only if the field does not exist" do
162
+ @client.hset("key1", "k1", "val1")
163
+ expect(@client.hsetnx("key1", "k1", "value")).to eq(false)
164
+ expect(@client.hsetnx("key1", "k2", "val2")).to eq(true)
165
+ expect(@client.hsetnx("key1", :k1, "value")).to eq(false)
166
+ expect(@client.hsetnx("key1", :k3, "val3")).to eq(true)
167
+
168
+ expect(@client.hget("key1", "k1")).to eq("val1")
169
+ expect(@client.hget("key1", "k2")).to eq("val2")
170
+ expect(@client.hget("key1", "k3")).to eq("val3")
171
+ end
172
+
173
+ it "should get all the values in a hash" do
174
+ @client.hset("key1", "k1", "val1")
175
+ @client.hset("key1", "k2", "val2")
176
+
177
+ expect(@client.hvals("key1")).to match_array(["val1", "val2"])
178
+ end
179
+
180
+ it "should accept a list of array pairs as arguments and not throw an invalid argument number error" do
181
+ @client.hmset("key1", [:k1, "val1"], [:k2, "val2"], [:k3, "val3"])
182
+ expect(@client.hget("key1", :k1)).to eq("val1")
183
+ expect(@client.hget("key1", :k2)).to eq("val2")
184
+ expect(@client.hget("key1", :k3)).to eq("val3")
185
+ end
186
+
187
+ it "should reject a list of arrays that contain an invalid number of arguments" do
188
+ expect { @client.hmset("key1", [:k1, "val1"], [:k2, "val2", "bogus val"]) }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for HMSET")
189
+ end
190
+
191
+ it "should convert a integer field name to string for hdel" do
192
+ @client.hset("key1", "1", 1)
193
+ expect(@client.hdel("key1", 1)).to be(1)
194
+ end
195
+
196
+ it "should convert a integer field name to string for hexists" do
197
+ @client.hset("key1", "1", 1)
198
+ expect(@client.hexists("key1", 1)).to be true
199
+ end
200
+
201
+ it "should convert a integer field name to string for hincrby" do
202
+ @client.hset("key1", 1, 0)
203
+ expect(@client.hincrby("key1", 1, 1)).to be(1)
204
+ end
205
+
206
+ describe "#hscan" do
207
+ it 'with no arguments and few items, returns all items' do
208
+ @client.hmset('hash', 'name', 'Jack', 'age', '33')
209
+ result = @client.hscan('hash', 0)
210
+
211
+ expect(result[0]).to eq('0')
212
+ expect(result[1]).to eq([['name', 'Jack'], ['age', '33']])
213
+ end
214
+
215
+ it 'with a count should return that number of members or more' do
216
+ @client.hmset('hash',
217
+ 'a', '1', 'b', '2', 'c', '3', 'd', '4', 'e', '5', 'f', '6', 'g', '7'
218
+ )
219
+ result = @client.hscan('hash', 0, count: 3)
220
+ expect(result[0]).to eq('3')
221
+ expect(result[1]).to eq([
222
+ ['a', '1'],
223
+ ['b', '2'],
224
+ ['c', '3'],
225
+ ])
226
+ end
227
+
228
+ it 'returns items starting at the provided cursor' do
229
+ @client.hmset('hash',
230
+ 'a', '1', 'b', '2', 'c', '3', 'd', '4', 'e', '5', 'f', '6', 'g', '7'
231
+ )
232
+ result = @client.hscan('hash', 2, count: 3)
233
+ expect(result[0]).to eq('5')
234
+ expect(result[1]).to eq([
235
+ ['c', '3'],
236
+ ['d', '4'],
237
+ ['e', '5']
238
+ ])
239
+ end
240
+
241
+ it 'with match, returns items matching the given pattern' do
242
+ @client.hmset('hash',
243
+ 'aa', '1', 'b', '2', 'cc', '3', 'd', '4', 'ee', '5', 'f', '6', 'gg', '7'
244
+ )
245
+ result = @client.hscan('hash', 2, count: 3, match: '??')
246
+ expect(result[0]).to eq('5')
247
+ expect(result[1]).to eq([
248
+ ['cc', '3'],
249
+ ['ee', '5']
250
+ ])
251
+ end
252
+
253
+ it 'returns an empty result if the key is not found' do
254
+ result = @client.hscan('hash', 0)
255
+
256
+ expect(result[0]).to eq('0')
257
+ expect(result[1]).to eq([])
258
+ end
259
+ end
260
+ end
261
+ end