Skip to content

Commit be99077

Browse files
committed
Add new RedisGeo Types
1 parent 58a55ea commit be99077

File tree

2 files changed

+13
-69
lines changed

2 files changed

+13
-69
lines changed

src/ServiceStack.Interfaces/Redis/RedisGeo.cs

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,20 @@
33

44
namespace ServiceStack.Redis
55
{
6-
public struct RedisGeo
6+
public class RedisGeo
77
{
8-
public double Longitude;
9-
public double Latitude;
10-
public string Member;
11-
12-
public RedisGeo(double longitude, double latitude, string member)
13-
{
14-
Longitude = longitude;
15-
Latitude = latitude;
16-
Member = member;
17-
}
18-
19-
public RedisGeo(string geoString) : this()
20-
{
21-
if (string.IsNullOrEmpty(geoString))
22-
throw new ArgumentNullException("geoString");
23-
24-
var pos1 = geoString.IndexOf(' ');
25-
if (pos1 == -1)
26-
throw new ArgumentException("Invalid geoString: " + geoString);
27-
Longitude = double.Parse(geoString.Substring(0, pos1));
28-
29-
var pos2 = geoString.IndexOf(' ', pos1 + 1);
30-
if (pos2 == -1)
31-
throw new ArgumentException("Invalid geoString: " + geoString);
32-
Latitude = double.Parse(geoString.Substring(pos1, pos2 - pos1));
33-
34-
Member = geoString.Substring(pos2 + 1);
35-
}
36-
37-
public override string ToString()
38-
{
39-
return Longitude.ToString(CultureInfo.InvariantCulture)
40-
+ " "
41-
+ Latitude.ToString(CultureInfo.InvariantCulture)
42-
+ " "
43-
+ Member;
44-
}
45-
46-
public bool Equals(RedisGeo other)
47-
{
48-
return Longitude.Equals(other.Longitude)
49-
&& Latitude.Equals(other.Latitude)
50-
&& string.Equals(Member, other.Member);
51-
}
52-
53-
public override bool Equals(object obj)
54-
{
55-
if (ReferenceEquals(null, obj)) return false;
56-
return obj is RedisGeo && Equals((RedisGeo) obj);
57-
}
8+
public double Longitude { get; set; }
9+
public double Latitude { get; set; }
10+
public string Member { get; set; }
11+
}
5812

59-
public override int GetHashCode()
60-
{
61-
unchecked
62-
{
63-
var hashCode = Longitude.GetHashCode();
64-
hashCode = (hashCode*397) ^ Latitude.GetHashCode();
65-
hashCode = (hashCode*397) ^ (Member != null ? Member.GetHashCode() : 0);
66-
return hashCode;
67-
}
68-
}
13+
public class RedisGeoResult
14+
{
15+
public string Member { get; set; }
16+
public double? Longitude { get; set; }
17+
public double? Latitude { get; set; }
18+
public string Hash { get; set; }
19+
public string Unit { get; set; }
20+
public double? Distance { get; set; }
6921
}
7022
}

tests/ServiceStack.Common.Tests/RedisTypeTests.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,5 @@ namespace ServiceStack.Common.Tests
66
[TestFixture]
77
public class RedisTypeTests
88
{
9-
[Test]
10-
public void Can_parse_RedisGeo()
11-
{
12-
var palermo = new RedisGeo(13.361389, 38.115556, "Palermo");
13-
var geoString = palermo.ToString();
14-
Assert.That(geoString, Is.EqualTo("13.361389 38.115556 Palermo"));
15-
Assert.That(new RedisGeo(geoString), Is.EqualTo(palermo));
16-
}
179
}
1810
}

0 commit comments

Comments
 (0)