fakeredis 0.5.0 → 0.8.0

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.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.travis.yml +14 -5
  4. data/LICENSE +1 -1
  5. data/README.md +42 -24
  6. data/fakeredis.gemspec +1 -1
  7. data/lib/fakeredis.rb +28 -0
  8. data/lib/fakeredis/bitop_command.rb +56 -0
  9. data/lib/fakeredis/command_executor.rb +6 -9
  10. data/lib/fakeredis/expiring_hash.rb +3 -5
  11. data/lib/fakeredis/geo_commands.rb +142 -0
  12. data/lib/fakeredis/geo_set.rb +84 -0
  13. data/lib/fakeredis/minitest.rb +24 -0
  14. data/lib/fakeredis/rspec.rb +1 -0
  15. data/lib/fakeredis/sort_method.rb +3 -3
  16. data/lib/fakeredis/sorted_set_store.rb +1 -1
  17. data/lib/fakeredis/transaction_commands.rb +2 -2
  18. data/lib/fakeredis/version.rb +1 -1
  19. data/lib/fakeredis/zset.rb +8 -2
  20. data/lib/redis/connection/memory.rb +650 -82
  21. data/spec/bitop_command_spec.rb +209 -0
  22. data/spec/command_executor_spec.rb +15 -0
  23. data/spec/compatibility_spec.rb +1 -1
  24. data/spec/connection_spec.rb +21 -21
  25. data/spec/fakeredis_spec.rb +73 -0
  26. data/spec/geo_set_spec.rb +164 -0
  27. data/spec/hashes_spec.rb +138 -57
  28. data/spec/hyper_log_logs_spec.rb +50 -0
  29. data/spec/keys_spec.rb +232 -90
  30. data/spec/lists_spec.rb +91 -35
  31. data/spec/memory_spec.rb +80 -7
  32. data/spec/server_spec.rb +38 -24
  33. data/spec/sets_spec.rb +112 -46
  34. data/spec/sort_method_spec.rb +6 -0
  35. data/spec/sorted_sets_spec.rb +482 -150
  36. data/spec/spec_helper.rb +9 -18
  37. data/spec/spec_helper_live_redis.rb +4 -4
  38. data/spec/strings_spec.rb +113 -79
  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 +20 -16
  42. data/spec/transactions_spec.rb +34 -13
  43. data/spec/upcase_method_name_spec.rb +2 -2
  44. metadata +23 -6
@@ -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
+ expect { @client.bitop("meh", "dest1", "key1") }.to 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
+ expect(@client.bitop("or", "dest1", "key1", "key2")).to eq(1)
32
+ expect(@client.bitcount("dest1")).to eq(3)
33
+ expect(@client.getbit("dest1", 0)).to eq(1)
34
+ expect(@client.getbit("dest1", 1)).to eq(1)
35
+ expect(@client.getbit("dest1", 2)).to eq(1)
36
+ expect(@client.getbit("dest1", 3)).to eq(0)
37
+ end
38
+
39
+ it "should apply bitwise or operation with empty values" do
40
+ @client.setbit("key1", 1, 1)
41
+
42
+ expect(@client.bitop("or", "dest1", "key1", "nothing_here1", "nothing_here2")).to eq(1)
43
+ expect(@client.bitcount("dest1")).to eq(1)
44
+ expect(@client.getbit("dest1", 0)).to eq(0)
45
+ expect(@client.getbit("dest1", 1)).to eq(1)
46
+ expect(@client.getbit("dest1", 2)).to eq(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
+ expect(@client.bitop("or", "dest1", "key1", "key2", "key3")).to eq(2)
60
+ expect(@client.bitcount("dest1")).to eq(6)
61
+ expect(@client.getbit("dest1", 1)).to eq(1)
62
+ expect(@client.getbit("dest1", 3)).to eq(1)
63
+ expect(@client.getbit("dest1", 5)).to eq(1)
64
+ expect(@client.getbit("dest1", 10)).to eq(1)
65
+ expect(@client.getbit("dest1", 13)).to eq(1)
66
+ expect(@client.getbit("dest1", 15)).to eq(1)
67
+ expect(@client.getbit("dest1", 2)).to eq(0)
68
+ expect(@client.getbit("dest1", 12)).to eq(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
+ expect(@client.bitop("and", "dest1", "key1", "key2")).to eq(1)
85
+ expect(@client.bitcount("dest1")).to eq(1)
86
+ expect(@client.getbit("dest1", 0)).to eq(0)
87
+ expect(@client.getbit("dest1", 1)).to eq(1)
88
+ expect(@client.getbit("dest1", 2)).to eq(0)
89
+ end
90
+
91
+ it "should apply bitwise and operation with empty values" do
92
+ @client.setbit("key1", 1, 1)
93
+
94
+ expect(@client.bitop("and", "dest1", "key1", "nothing_here")).to eq(1)
95
+ expect(@client.bitcount("dest1")).to eq(1)
96
+ expect(@client.getbit("dest1", 0)).to eq(0)
97
+ expect(@client.getbit("dest1", 1)).to eq(1)
98
+ expect(@client.getbit("dest1", 2)).to eq(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
+ expect(@client.bitop("and", "dest1", "key1", "key2", "key3")).to eq(1)
118
+ expect(@client.bitcount("dest1")).to eq(2)
119
+ expect(@client.getbit("dest1", 1)).to eq(0)
120
+ expect(@client.getbit("dest1", 2)).to eq(1)
121
+ expect(@client.getbit("dest1", 3)).to eq(0)
122
+ expect(@client.getbit("dest1", 4)).to eq(1)
123
+ expect(@client.getbit("dest1", 5)).to eq(0)
124
+ expect(@client.getbit("dest1", 6)).to eq(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
+ expect(@client.bitop("xor", "dest1", "key1", "key2")).to eq(1)
143
+ expect(@client.bitcount("dest1")).to eq(2)
144
+ expect(@client.getbit("dest1", 0)).to eq(1)
145
+ expect(@client.getbit("dest1", 1)).to eq(0)
146
+ expect(@client.getbit("dest1", 2)).to eq(1)
147
+ expect(@client.getbit("dest1", 3)).to eq(0)
148
+ end
149
+
150
+ it "should apply bitwise xor operation with empty values" do
151
+ @client.setbit("key1", 1, 1)
152
+
153
+ expect(@client.bitop("xor", "dest1", "key1", "nothing_here1", "nothing_here2")).to eq(1)
154
+ expect(@client.bitcount("dest1")).to eq(1)
155
+ expect(@client.getbit("dest1", 0)).to eq(0)
156
+ expect(@client.getbit("dest1", 1)).to eq(1)
157
+ expect(@client.getbit("dest1", 2)).to eq(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
+ expect(@client.bitop("xor", "dest1", "key1", "key2")).to eq(1)
172
+ expect(@client.bitcount("dest1")).to eq(4)
173
+ expect(@client.getbit("dest1", 1)).to eq(1)
174
+ expect(@client.getbit("dest1", 2)).to eq(1)
175
+ expect(@client.getbit("dest1", 3)).to eq(0)
176
+ expect(@client.getbit("dest1", 4)).to eq(1)
177
+ expect(@client.getbit("dest1", 5)).to eq(1)
178
+ expect(@client.getbit("dest1", 6)).to eq(0)
179
+ end
180
+ end
181
+
182
+ describe "not" do
183
+ it 'raises an argument error when not passed any keys' do
184
+ expect { @client.bitop("not", "destkey") }.to raise_error(Redis::CommandError)
185
+ end
186
+
187
+ it 'raises an argument error when not passed too many keys' do
188
+ expect { @client.bitop("not", "destkey", "key1", "key2") }.to 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
+ expect(@client.bitop("not", "dest1", "key1")).to eq(1)
197
+ expect(@client.bitcount("dest1")).to eq(5)
198
+ expect(@client.getbit("dest1", 0)).to eq(1)
199
+ expect(@client.getbit("dest1", 1)).to eq(0)
200
+ expect(@client.getbit("dest1", 2)).to eq(1)
201
+ expect(@client.getbit("dest1", 3)).to eq(0)
202
+ expect(@client.getbit("dest1", 4)).to eq(1)
203
+ expect(@client.getbit("dest1", 5)).to eq(0)
204
+ expect(@client.getbit("dest1", 6)).to eq(1)
205
+ expect(@client.getbit("dest1", 7)).to eq(1)
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe FakeRedis::CommandExecutor do
4
+
5
+ let(:redis) { Redis.new }
6
+
7
+ context '#write' do
8
+ it 'does not modify its argument' do
9
+ command = [:get, 'key']
10
+ redis.write(command)
11
+ expect(command).to eql([:get, 'key'])
12
+ end
13
+ end
14
+
15
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module FakeRedis
4
4
  describe "Compatibility" do
5
5
  it "should be accessible through FakeRedis::Redis" do
6
- lambda { FakeRedis::Redis.new }.should_not raise_error
6
+ expect { FakeRedis::Redis.new }.not_to raise_error
7
7
  end
8
8
  end
9
9
  end
@@ -9,7 +9,7 @@ module FakeRedis
9
9
 
10
10
  if fakeredis?
11
11
  it "should authenticate to the server" do
12
- @client.auth("pass").should be == "OK"
12
+ expect(@client.auth("pass")).to eq("OK")
13
13
  end
14
14
 
15
15
  it "should re-use the same instance with the same host & port" do
@@ -18,40 +18,40 @@ module FakeRedis
18
18
  @client3 = Redis.new(:host => "localhost", :port => 5678)
19
19
 
20
20
  @client1.set("key1", "1")
21
- @client2.get("key1").should be == "1"
22
- @client3.get("key1").should be_nil
21
+ expect(@client2.get("key1")).to eq("1")
22
+ expect(@client3.get("key1")).to be_nil
23
23
 
24
24
  @client2.set("key2", "2")
25
- @client1.get("key2").should be == "2"
26
- @client3.get("key2").should be_nil
25
+ expect(@client1.get("key2")).to eq("2")
26
+ expect(@client3.get("key2")).to be_nil
27
27
 
28
28
  @client3.set("key3", "3")
29
- @client1.get("key3").should be_nil
30
- @client2.get("key3").should be_nil
29
+ expect(@client1.get("key3")).to be_nil
30
+ expect(@client2.get("key3")).to be_nil
31
31
 
32
- @client1.dbsize.should be == 2
33
- @client2.dbsize.should be == 2
34
- @client3.dbsize.should be == 1
32
+ expect(@client1.dbsize).to eq(2)
33
+ expect(@client2.dbsize).to eq(2)
34
+ expect(@client3.dbsize).to eq(1)
35
35
  end
36
36
 
37
37
  it "should connect to a specific database" do
38
38
  @client1 = Redis.new(:host => "localhost", :port => 1234, :db => 0)
39
39
  @client1.set("key1", "1")
40
40
  @client1.select(0)
41
- @client1.get("key1").should be == "1"
41
+ expect(@client1.get("key1")).to eq("1")
42
42
 
43
43
  @client2 = Redis.new(:host => "localhost", :port => 1234, :db => 1)
44
44
  @client2.set("key1", "1")
45
45
  @client2.select(1)
46
- @client2.get("key1").should == "1"
46
+ expect(@client2.get("key1")).to eq("1")
47
47
  end
48
48
 
49
49
  it "should not error with shutdown" do
50
- lambda { @client.shutdown }.should_not raise_error
50
+ expect { @client.shutdown }.not_to raise_error
51
51
  end
52
52
 
53
53
  it "should not error with quit" do
54
- lambda { @client.quit }.should_not raise_error
54
+ expect { @client.quit }.not_to raise_error
55
55
  end
56
56
  end
57
57
 
@@ -60,26 +60,26 @@ module FakeRedis
60
60
  @client2 = Redis.new(:host => "localhost", :port => 6379, :db => 2)
61
61
 
62
62
  @client1.set("key1", "one")
63
- @client1.get("key1").should be == "one"
63
+ expect(@client1.get("key1")).to eq("one")
64
64
 
65
65
  @client2.set("key2", "two")
66
- @client2.get("key2").should be == "two"
66
+ expect(@client2.get("key2")).to eq("two")
67
67
 
68
- @client1.get("key1").should be == "one"
68
+ expect(@client1.get("key1")).to eq("one")
69
69
  end
70
70
 
71
71
  it "should not error with a disconnected client" do
72
72
  @client1 = Redis.new
73
- @client1.client.disconnect
74
- @client1.get("key1").should be_nil
73
+ @client1.close
74
+ expect(@client1.get("key1")).to be_nil
75
75
  end
76
76
 
77
77
  it "should echo the given string" do
78
- @client.echo("something").should == "something"
78
+ expect(@client.echo("something")).to eq("something")
79
79
  end
80
80
 
81
81
  it "should ping the server" do
82
- @client.ping.should == "PONG"
82
+ expect(@client.ping).to eq("PONG")
83
83
  end
84
84
  end
85
85
  end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe FakeRedis do
4
+ after { described_class.disable }
5
+
6
+ describe '.enable' do
7
+ it 'in memory connection' do
8
+ described_class.enable
9
+ expect(described_class.enabled?).to be_truthy
10
+ end
11
+ end
12
+
13
+ describe '.disable' do
14
+ before { described_class.enable }
15
+
16
+ it 'in memory connection' do
17
+ described_class.disable
18
+ expect(described_class.enabled?).to be_falsy
19
+ end
20
+ end
21
+
22
+ describe '.disabling' do
23
+ context 'FakeRedis is enabled' do
24
+ before { described_class.enable }
25
+
26
+ it 'in memory connection' do
27
+ described_class.disabling do
28
+ expect(described_class.enabled?).to be_falsy
29
+ end
30
+
31
+ expect(described_class.enabled?).to be_truthy
32
+ end
33
+ end
34
+
35
+ context 'FakeRedis is disabled' do
36
+ before { described_class.disable }
37
+
38
+ it 'in memory connection' do
39
+ described_class.disabling do
40
+ expect(described_class.enabled?).to be_falsy
41
+ end
42
+
43
+ expect(described_class.enabled?).to be_falsy
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '.enabling' do
49
+ context 'FakeRedis is enabled' do
50
+ before { described_class.enable }
51
+
52
+ it 'in memory connection' do
53
+ described_class.enabling do
54
+ expect(described_class.enabled?).to be_truthy
55
+ end
56
+
57
+ expect(described_class.enabled?).to be_truthy
58
+ end
59
+ end
60
+
61
+ context 'FakeRedis is disabled' do
62
+ before { described_class.disable }
63
+
64
+ it 'in memory connection' do
65
+ described_class.enabling do
66
+ expect(described_class.enabled?).to be_truthy
67
+ end
68
+
69
+ expect(described_class.enabled?).to be_falsy
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,164 @@
1
+ require "spec_helper"
2
+
3
+ module FakeRedis
4
+ describe "GeoMethods" do
5
+ before do
6
+ @client = Redis.new
7
+ end
8
+
9
+ describe "#geoadd" do
10
+ it "should raise when not enough arguments" do
11
+ expect { @client.geoadd("Sicily", []) }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for 'geoadd' command")
12
+ expect { @client.geoadd("Sicily", [13.361389, 38.115556]) }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for 'geoadd' command")
13
+ end
14
+
15
+ it "should add items to the set" do
16
+ added_items_count = add_sicily
17
+ expect(added_items_count).to eq(2)
18
+ end
19
+
20
+ it "should update existing items" do
21
+ @client.geoadd("Sicily", 13.361389, 38.115556, "Palermo")
22
+ added_items_count = @client.geoadd("Sicily", 13, 39, "Palermo", 15.087269, 37.502669, "Catania")
23
+ expect(added_items_count).to eq(1)
24
+ end
25
+ end
26
+
27
+ describe "#geodist" do
28
+ before do
29
+ add_sicily
30
+ end
31
+
32
+ it "should return destination between two elements" do
33
+ distance_in_meters = @client.geodist("Sicily", "Palermo", "Catania")
34
+ expect(distance_in_meters).to eq("166412.6051")
35
+
36
+ distance_in_feet = @client.geodist("Sicily", "Palermo", "Catania", "ft")
37
+ expect(distance_in_feet).to eq("545973.1137")
38
+ end
39
+
40
+ it "should raise for unknown unit name" do
41
+ expect {
42
+ @client.geodist("Sicily", "Palermo", "Catania", "unknown")
43
+ }.to raise_error(Redis::CommandError, "ERR unsupported unit provided. please use m, km, ft, mi")
44
+ end
45
+
46
+ it "should return nil when element is missing" do
47
+ expect(@client.geodist("Sicily", "Palermo", "Rome")).to be_nil
48
+ end
49
+ end
50
+
51
+ describe "#geohash" do
52
+ before do
53
+ add_sicily
54
+ end
55
+
56
+ it "should raise when not enough arguments" do
57
+ expect { @client.geohash("Sicily", []) }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for 'geohash' command")
58
+ end
59
+
60
+ it "should return geohashes" do
61
+ geohash = @client.geohash("Sicily", "Palermo")
62
+ expect(geohash).to eq(["sqc8b49rny"])
63
+
64
+ geohashes = @client.geohash("Sicily", ["Palermo", "Catania"])
65
+ expect(geohashes).to eq(["sqc8b49rny", "sqdtr74hyu"])
66
+ end
67
+
68
+ it "should return nils for nonexistent elements" do
69
+ geohashes = @client.geohash("Sicily", ["Palermo", "Rome"])
70
+ expect(geohashes).to eq(["sqc8b49rny", nil])
71
+ end
72
+ end
73
+
74
+ describe "#geopos" do
75
+ it "should return positions (longitude, latitude) for elements" do
76
+ add_sicily
77
+ position = @client.geopos("Sicily", "Catania")
78
+ expect(position).to eq([["15.087269", "37.502669"]])
79
+
80
+ positions = @client.geopos("Sicily", ["Palermo", "Catania"])
81
+ expect(positions).to eq([["13.361389", "38.115556"], ["15.087269", "37.502669"]])
82
+ end
83
+
84
+ it "should return nil for nonexistent elements" do
85
+ expect(@client.geopos("nonexistent", "nonexistent2")).to be_nil
86
+ add_sicily
87
+
88
+ position = @client.geopos("Sicily", "Rome")
89
+ expect(position).to eq([nil])
90
+
91
+ positions = @client.geopos("Sicily", ["Rome", "Catania"])
92
+ expect(positions).to eq([nil, ["15.087269", "37.502669"]])
93
+ end
94
+ end
95
+
96
+ describe "#georadius" do
97
+ before do
98
+ add_sicily
99
+ end
100
+
101
+ it "should return members within specified radius" do
102
+ nearest_cities = @client.georadius("Sicily", 15, 37, 100, "km")
103
+ expect(nearest_cities).to eq(["Catania"])
104
+ end
105
+
106
+ it "should sort returned members" do
107
+ nearest_cities = @client.georadius("Sicily", 15, 37, 200, "km", sort: "asc")
108
+ expect(nearest_cities).to eq(["Catania", "Palermo"])
109
+
110
+ farthest_cities = @client.georadius("Sicily", 15, 37, 200, "km", sort: "desc")
111
+ expect(farthest_cities).to eq(["Palermo", "Catania"])
112
+ end
113
+
114
+ it "should return specified count of members" do
115
+ city = @client.georadius("Sicily", 15, 37, 200, "km", sort: "asc", count: 1)
116
+ expect(city).to eq(["Catania"])
117
+ end
118
+
119
+ it "should include additional info for members" do
120
+ cities = @client.georadius("Sicily", 15, 37, 200, "km", "WITHDIST")
121
+ expect(cities).to eq([["Palermo", "190.6009"], ["Catania", "56.4883"]])
122
+
123
+ cities = @client.georadius("Sicily", 15, 37, 200, "km", "WITHCOORD")
124
+ expect(cities).to eq [["Palermo", ["13.361389", "38.115556"]], ["Catania", ["15.087269", "37.502669"]]]
125
+
126
+ cities = @client.georadius("Sicily", 15, 37, 200, "km", "WITHDIST", "WITHCOORD")
127
+ expect(cities).to eq(
128
+ [["Palermo", "190.6009", ["13.361389", "38.115556"]],
129
+ ["Catania", "56.4883", ["15.087269", "37.502669"]]]
130
+ )
131
+ end
132
+ end
133
+
134
+ describe "#georadiusbymember" do
135
+ before do
136
+ add_sicily
137
+ end
138
+
139
+ it "should sort returned members" do
140
+ nearest_cities = @client.georadiusbymember("Sicily", "Catania", 200, "km", sort: "asc")
141
+ expect(nearest_cities).to eq(["Catania", "Palermo"])
142
+
143
+ farthest_cities = @client.georadiusbymember("Sicily", "Catania", 200, "km", sort: "desc")
144
+ expect(farthest_cities).to eq(["Palermo", "Catania"])
145
+ end
146
+
147
+ it "should limit number of returned members" do
148
+ city = @client.georadiusbymember("Sicily", "Catania", 100, "km", count: 1)
149
+ expect(city).to eq(["Catania"])
150
+ end
151
+
152
+ it "should include extra info if requested" do
153
+ city = @client.georadiusbymember("Sicily", "Catania", 200, "km", sort: :desc, options: :WITHDIST, count: 1)
154
+ expect(city).to eq([["Palermo", "166.4126"]])
155
+ end
156
+ end
157
+
158
+ private
159
+
160
+ def add_sicily
161
+ @client.geoadd("Sicily", 13.361389, 38.115556, "Palermo", 15.087269, 37.502669, "Catania")
162
+ end
163
+ end
164
+ end