Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit e8a63bc

Browse files
authored
Merge pull request #235 from xperiandri/master
Fixes issue with GeoRadius when server culture is different from EN-US
2 parents b28808a + e1ff3be commit e8a63bc

3 files changed

Lines changed: 57 additions & 55 deletions

File tree

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Globalization;
23

34
namespace ServiceStack.Redis
45
{
@@ -19,28 +20,28 @@ public static RedisText ToRedisText(this RedisData data)
1920
return to;
2021
}
2122

22-
public static string GetResult(this RedisText from)
23-
{
24-
return from.Text;
25-
}
23+
public static double ToDouble(this RedisData data)
24+
=> double.Parse(data.Data.FromUtf8Bytes(),
25+
NumberStyles.Float,
26+
CultureInfo.InvariantCulture);
2627

27-
public static T GetResult<T>(this RedisText from)
28-
{
29-
return from.Text.FromJson<T>();
30-
}
28+
public static long ToInt64(this RedisData data)
29+
=> long.Parse(data.Data.FromUtf8Bytes(),
30+
NumberStyles.Integer,
31+
CultureInfo.InvariantCulture);
32+
33+
public static string GetResult(this RedisText from) => from.Text;
34+
35+
public static T GetResult<T>(this RedisText from) => from.Text.FromJson<T>();
3136

3237
public static List<string> GetResults(this RedisText from)
33-
{
34-
return from.Children == null
35-
? new List<string>()
36-
: from.Children.ConvertAll(x => x.Text);
37-
}
38+
=> from.Children == null
39+
? new List<string>()
40+
: from.Children.ConvertAll(x => x.Text);
3841

3942
public static List<T> GetResults<T>(this RedisText from)
40-
{
41-
return from.Children == null
42-
? new List<T>()
43-
: from.Children.ConvertAll(x => x.Text.FromJson<T>());
44-
}
43+
=> from.Children == null
44+
? new List<T>()
45+
: from.Children.ConvertAll(x => x.Text.FromJson<T>());
4546
}
4647
}

src/ServiceStack.Redis/RedisNativeClient.cs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace ServiceStack.Redis
2727
/// <summary>
2828
/// This class contains all the common operations for the RedisClient.
2929
/// The client contains a 1:1 mapping of c# methods to redis operations of the same name.
30-
///
30+
///
3131
/// Not threadsafe use a pooled manager
3232
/// </summary>
3333
public partial class RedisNativeClient
@@ -105,7 +105,7 @@ internal bool Active
105105
private TimeSpan retryTimeout;
106106
public int RetryTimeout
107107
{
108-
get { return (int) retryTimeout.TotalMilliseconds; }
108+
get { return (int)retryTimeout.TotalMilliseconds; }
109109
set { retryTimeout = TimeSpan.FromMilliseconds(value); }
110110
}
111111
public int RetryCount { get; set; }
@@ -897,9 +897,9 @@ public void ClientKill(string clientAddr)
897897
public long ClientKill(string addr = null, string id = null, string type = null, string skipMe = null)
898898
{
899899
var cmdWithArgs = new List<byte[]>
900-
{
901-
Commands.Client, Commands.Kill,
902-
};
900+
{
901+
Commands.Client, Commands.Kill,
902+
};
903903

904904
if (addr != null)
905905
{
@@ -1258,9 +1258,9 @@ public byte[][] LRange(string listId, int startingFrom, int endingAt)
12581258
public byte[][] Sort(string listOrSetId, SortOptions sortOptions)
12591259
{
12601260
var cmdWithArgs = new List<byte[]>
1261-
{
1262-
Commands.Sort, listOrSetId.ToUtf8Bytes()
1263-
};
1261+
{
1262+
Commands.Sort, listOrSetId.ToUtf8Bytes()
1263+
};
12641264

12651265
if (sortOptions.SortPattern != null)
12661266
{
@@ -1702,9 +1702,9 @@ private byte[][] GetRange(byte[] commandBytes, string setId, int min, int max, b
17021702
throw new ArgumentNullException("setId");
17031703

17041704
var cmdWithArgs = new List<byte[]>
1705-
{
1706-
commandBytes, setId.ToUtf8Bytes(), min.ToUtf8Bytes(), max.ToUtf8Bytes()
1707-
};
1705+
{
1706+
commandBytes, setId.ToUtf8Bytes(), min.ToUtf8Bytes(), max.ToUtf8Bytes()
1707+
};
17081708

17091709
if (withScores)
17101710
{
@@ -1741,9 +1741,9 @@ private byte[][] GetRangeByScore(byte[] commandBytes,
17411741
throw new ArgumentNullException("setId");
17421742

17431743
var cmdWithArgs = new List<byte[]>
1744-
{
1745-
commandBytes, setId.ToUtf8Bytes(), min.ToFastUtf8Bytes(), max.ToFastUtf8Bytes()
1746-
};
1744+
{
1745+
commandBytes, setId.ToUtf8Bytes(), min.ToFastUtf8Bytes(), max.ToFastUtf8Bytes()
1746+
};
17471747

17481748
if (skip.HasValue || take.HasValue)
17491749
{
@@ -1767,9 +1767,9 @@ private byte[][] GetRangeByScore(byte[] commandBytes,
17671767
throw new ArgumentNullException("setId");
17681768

17691769
var cmdWithArgs = new List<byte[]>
1770-
{
1771-
commandBytes, setId.ToUtf8Bytes(), min.ToUtf8Bytes(), max.ToUtf8Bytes()
1772-
};
1770+
{
1771+
commandBytes, setId.ToUtf8Bytes(), min.ToUtf8Bytes(), max.ToUtf8Bytes()
1772+
};
17731773

17741774
if (skip.HasValue || take.HasValue)
17751775
{
@@ -1937,9 +1937,9 @@ public byte[][] ZRangeByLex(string setId, string min, string max, int? skip = nu
19371937
throw new ArgumentNullException("setId");
19381938

19391939
var cmdWithArgs = new List<byte[]>
1940-
{
1941-
Commands.ZRangeByLex, setId.ToUtf8Bytes(), min.ToUtf8Bytes(), max.ToUtf8Bytes()
1942-
};
1940+
{
1941+
Commands.ZRangeByLex, setId.ToUtf8Bytes(), min.ToUtf8Bytes(), max.ToUtf8Bytes()
1942+
};
19431943

19441944
if (skip.HasValue || take.HasValue)
19451945
{
@@ -2236,13 +2236,15 @@ public List<RedisGeo> GeoPos(string key, params string[] members)
22362236
break;
22372237

22382238
var entry = data.Children[i];
2239-
if (entry.Children.Count == 0)
2239+
2240+
var children = entry.Children;
2241+
if (children.Count == 0)
22402242
continue;
22412243

22422244
to.Add(new RedisGeo
22432245
{
2244-
Longitude = double.Parse(entry.Children[0].Data.FromUtf8Bytes()),
2245-
Latitude = double.Parse(entry.Children[1].Data.FromUtf8Bytes()),
2246+
Longitude = children[0].ToDouble(),
2247+
Latitude = children[1].ToDouble(),
22462248
Member = members[i],
22472249
});
22482250
}
@@ -2303,16 +2305,15 @@ public List<RedisGeoResult> GeoRadius(string key, double longitude, double latit
23032305
var i = 0;
23042306
var result = new RedisGeoResult { Unit = unit, Member = child.Children[i++].Data.FromUtf8Bytes() };
23052307

2306-
if (withDist)
2307-
result.Distance = double.Parse(child.Children[i++].Data.FromUtf8Bytes());
2308+
if (withDist) result.Distance = child.Children[i++].ToDouble();
23082309

2309-
if (withHash)
2310-
result.Hash = long.Parse(child.Children[i++].Data.FromUtf8Bytes());
2310+
if (withHash) result.Hash = child.Children[i++].ToInt64();
23112311

23122312
if (withCoords)
23132313
{
2314-
result.Longitude = double.Parse(child.Children[i].Children[0].Data.FromUtf8Bytes());
2315-
result.Latitude = double.Parse(child.Children[i].Children[1].Data.FromUtf8Bytes());
2314+
var children = child.Children[i].Children;
2315+
result.Longitude = children[0].ToDouble();
2316+
result.Latitude = children[1].ToDouble();
23162317
}
23172318

23182319
to.Add(result);
@@ -2322,7 +2323,7 @@ public List<RedisGeoResult> GeoRadius(string key, double longitude, double latit
23222323
return to;
23232324
}
23242325

2325-
public List<RedisGeoResult> GeoRadiusByMember(string key, string member, double radius, string unit,
2326+
public List<RedisGeoResult> GeoRadiusByMember(string key, string member, double radius, string unit,
23262327
bool withCoords = false, bool withDist = false, bool withHash = false, int? count = null, bool? asc = null)
23272328
{
23282329
if (key == null)
@@ -2374,16 +2375,15 @@ public List<RedisGeoResult> GeoRadiusByMember(string key, string member, double
23742375
var i = 0;
23752376
var result = new RedisGeoResult { Unit = unit, Member = child.Children[i++].Data.FromUtf8Bytes() };
23762377

2377-
if (withDist)
2378-
result.Distance = double.Parse(child.Children[i++].Data.FromUtf8Bytes());
2378+
if (withDist) result.Distance = child.Children[i++].ToDouble();
23792379

2380-
if (withHash)
2381-
result.Hash = long.Parse(child.Children[i++].Data.FromUtf8Bytes());
2380+
if (withHash) result.Hash = child.Children[i++].ToInt64();
23822381

23832382
if (withCoords)
23842383
{
2385-
result.Longitude = double.Parse(child.Children[i].Children[0].Data.FromUtf8Bytes());
2386-
result.Latitude = double.Parse(child.Children[i].Children[1].Data.FromUtf8Bytes());
2384+
var children = child.Children[i].Children;
2385+
result.Longitude = children[0].ToDouble();
2386+
result.Latitude = children[1].ToDouble();
23872387
}
23882388

23892389
to.Add(result);

src/ServiceStack.Redis/ScanResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Globalization;
23

34
namespace ServiceStack.Redis
45
{
@@ -15,7 +16,7 @@ public static Dictionary<string, double> AsItemsWithScores(this ScanResult resul
1516
for (var i = 0; i < result.Results.Count; i += 2)
1617
{
1718
var key = result.Results[i];
18-
var score = double.Parse(result.Results[i + 1].FromUtf8Bytes());
19+
var score = result.Results[i + 1].ToDouble();
1920
to[key.FromUtf8Bytes()] = score;
2021
}
2122
return to;

0 commit comments

Comments
 (0)