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

Commit be6a5ab

Browse files
committed
Fixed RedisData parsing with regard to a current system culture.
As Redis uses InvariantCulture and data passed in this culture it must be parsed with InvariantCulture to to prevent issues on non EN-US culture computers.
1 parent b28808a commit be6a5ab

2 files changed

Lines changed: 55 additions & 32 deletions

File tree

src/ServiceStack.Redis/RedisNativeClient.cs

Lines changed: 51 additions & 31 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
{
@@ -2241,8 +2241,12 @@ public List<RedisGeo> GeoPos(string key, params string[] members)
22412241

22422242
to.Add(new RedisGeo
22432243
{
2244-
Longitude = double.Parse(entry.Children[0].Data.FromUtf8Bytes()),
2245-
Latitude = double.Parse(entry.Children[1].Data.FromUtf8Bytes()),
2244+
Longitude = double.Parse(entry.Children[0].Data.FromUtf8Bytes(),
2245+
NumberStyles.Float,
2246+
CultureInfo.InvariantCulture),
2247+
Latitude = double.Parse(entry.Children[1].Data.FromUtf8Bytes(),
2248+
NumberStyles.Float,
2249+
CultureInfo.InvariantCulture),
22462250
Member = members[i],
22472251
});
22482252
}
@@ -2304,15 +2308,23 @@ public List<RedisGeoResult> GeoRadius(string key, double longitude, double latit
23042308
var result = new RedisGeoResult { Unit = unit, Member = child.Children[i++].Data.FromUtf8Bytes() };
23052309

23062310
if (withDist)
2307-
result.Distance = double.Parse(child.Children[i++].Data.FromUtf8Bytes());
2311+
result.Distance = double.Parse(child.Children[i++].Data.FromUtf8Bytes(),
2312+
NumberStyles.Float,
2313+
CultureInfo.InvariantCulture);
23082314

23092315
if (withHash)
2310-
result.Hash = long.Parse(child.Children[i++].Data.FromUtf8Bytes());
2316+
result.Hash = long.Parse(child.Children[i++].Data.FromUtf8Bytes(),
2317+
NumberStyles.Integer,
2318+
CultureInfo.InvariantCulture);
23112319

23122320
if (withCoords)
23132321
{
2314-
result.Longitude = double.Parse(child.Children[i].Children[0].Data.FromUtf8Bytes());
2315-
result.Latitude = double.Parse(child.Children[i].Children[1].Data.FromUtf8Bytes());
2322+
result.Longitude = double.Parse(child.Children[i].Children[0].Data.FromUtf8Bytes(),
2323+
NumberStyles.Float,
2324+
CultureInfo.InvariantCulture);
2325+
result.Latitude = double.Parse(child.Children[i].Children[1].Data.FromUtf8Bytes(),
2326+
NumberStyles.Float,
2327+
CultureInfo.InvariantCulture);
23162328
}
23172329

23182330
to.Add(result);
@@ -2322,7 +2334,7 @@ public List<RedisGeoResult> GeoRadius(string key, double longitude, double latit
23222334
return to;
23232335
}
23242336

2325-
public List<RedisGeoResult> GeoRadiusByMember(string key, string member, double radius, string unit,
2337+
public List<RedisGeoResult> GeoRadiusByMember(string key, string member, double radius, string unit,
23262338
bool withCoords = false, bool withDist = false, bool withHash = false, int? count = null, bool? asc = null)
23272339
{
23282340
if (key == null)
@@ -2375,15 +2387,23 @@ public List<RedisGeoResult> GeoRadiusByMember(string key, string member, double
23752387
var result = new RedisGeoResult { Unit = unit, Member = child.Children[i++].Data.FromUtf8Bytes() };
23762388

23772389
if (withDist)
2378-
result.Distance = double.Parse(child.Children[i++].Data.FromUtf8Bytes());
2390+
result.Distance = double.Parse(child.Children[i++].Data.FromUtf8Bytes(),
2391+
NumberStyles.Float,
2392+
CultureInfo.InvariantCulture);
23792393

23802394
if (withHash)
2381-
result.Hash = long.Parse(child.Children[i++].Data.FromUtf8Bytes());
2395+
result.Hash = long.Parse(child.Children[i++].Data.FromUtf8Bytes(),
2396+
NumberStyles.Integer,
2397+
CultureInfo.InvariantCulture);
23822398

23832399
if (withCoords)
23842400
{
2385-
result.Longitude = double.Parse(child.Children[i].Children[0].Data.FromUtf8Bytes());
2386-
result.Latitude = double.Parse(child.Children[i].Children[1].Data.FromUtf8Bytes());
2401+
result.Longitude = double.Parse(child.Children[i].Children[0].Data.FromUtf8Bytes(),
2402+
NumberStyles.Float,
2403+
CultureInfo.InvariantCulture);
2404+
result.Latitude = double.Parse(child.Children[i].Children[1].Data.FromUtf8Bytes(),
2405+
NumberStyles.Float,
2406+
CultureInfo.InvariantCulture);
23872407
}
23882408

23892409
to.Add(result);

src/ServiceStack.Redis/ScanResult.cs

Lines changed: 4 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,9 @@ 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 = double.Parse(result.Results[i + 1].FromUtf8Bytes(),
20+
NumberStyles.Float,
21+
CultureInfo.InvariantCulture);
1922
to[key.FromUtf8Bytes()] = score;
2023
}
2124
return to;

0 commit comments

Comments
 (0)