Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
f347cf61
Commit
f347cf61
authored
Jun 28, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix relative sorting of values
parent
75d1257d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
15 deletions
+44
-15
RedisValue.cs
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
+44
-15
No files found.
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
View file @
f347cf61
...
...
@@ -104,6 +104,21 @@ public bool IsNullOrEmpty
}
}
// if either is a numeric type, and the other isn't the *same* type (above), then:
// it can't be equal
switch
(
xType
)
{
case
StorageType
.
Int64
:
case
StorageType
.
Double
:
return
false
;
}
switch
(
yType
)
{
case
StorageType
.
Int64
:
case
StorageType
.
Double
:
return
false
;
}
// otherwise, compare as strings
return
(
string
)
x
==
(
string
)
y
;
}
...
...
@@ -292,33 +307,47 @@ internal StorageType Type
/// Compare against a RedisValue for relative order
/// </summary>
/// <param name="other">The other <see cref="RedisValue"/> to compare.</param>
public
int
CompareTo
(
RedisValue
other
)
public
int
CompareTo
(
RedisValue
other
)
=>
CompareTo
(
this
,
other
);
static
int
CompareTo
(
RedisValue
x
,
RedisValue
y
)
{
try
{
StorageType
thisType
=
this
.
Type
,
otherType
=
other
.
Type
;
x
=
x
.
Simplify
();
y
=
y
.
Simplify
();
StorageType
xType
=
x
.
Type
,
yType
=
y
.
Type
;
if
(
thisType
==
StorageType
.
Null
)
return
other
Type
==
StorageType
.
Null
?
0
:
-
1
;
if
(
other
Type
==
StorageType
.
Null
)
return
1
;
if
(
xType
==
StorageType
.
Null
)
return
y
Type
==
StorageType
.
Null
?
0
:
-
1
;
if
(
y
Type
==
StorageType
.
Null
)
return
1
;
if
(
thisType
==
other
Type
)
if
(
xType
==
y
Type
)
{
switch
(
this
Type
)
switch
(
x
Type
)
{
case
StorageType
.
Double
:
return
this
.
OverlappedValueDouble
.
CompareTo
(
other
.
OverlappedValueDouble
);
return
x
.
OverlappedValueDouble
.
CompareTo
(
y
.
OverlappedValueDouble
);
case
StorageType
.
Int64
:
return
this
.
_overlappedValue64
.
CompareTo
(
other
.
_overlappedValue64
);
return
x
.
_overlappedValue64
.
CompareTo
(
y
.
_overlappedValue64
);
case
StorageType
.
String
:
return
string
.
CompareOrdinal
((
string
)
this
.
_objectOrSentinel
,
(
string
)
other
.
_objectOrSentinel
);
return
string
.
CompareOrdinal
((
string
)
x
.
_objectOrSentinel
,
(
string
)
y
.
_objectOrSentinel
);
case
StorageType
.
Raw
:
return
this
.
_memory
.
Span
.
SequenceCompareTo
(
other
.
_memory
.
Span
);
return
x
.
_memory
.
Span
.
SequenceCompareTo
(
y
.
_memory
.
Span
);
}
}
switch
(
xType
)
{
// numbers can be compared between Int64/Double
case
StorageType
.
Double
:
if
(
yType
==
StorageType
.
Int64
)
return
x
.
OverlappedValueDouble
.
CompareTo
((
double
)
y
.
_overlappedValue64
);
break
;
case
StorageType
.
Int64
:
if
(
yType
==
StorageType
.
Double
)
return
((
double
)
x
.
_overlappedValue64
).
CompareTo
(
y
.
OverlappedValueDouble
);
break
;
}
// otherwise, compare as strings
return
string
.
CompareOrdinal
((
string
)
this
,
(
string
)
other
);
return
string
.
CompareOrdinal
((
string
)
x
,
(
string
)
y
);
}
catch
(
Exception
ex
)
{
...
...
@@ -545,7 +574,7 @@ private static bool TryParseDouble(ReadOnlySpan<byte> blob, out double value)
/// <param name="value">The <see cref="RedisValue"/> to convert.</param>
public
static
explicit
operator
bool
?
(
RedisValue
value
)
=>
value
.
IsNull
?
(
bool
?)
null
:
(
bool
)
value
;
/// <summary>
/// Converts a <see cref="RedisValue"/> to a <see cref="string"/>.
/// </summary>
...
...
@@ -693,7 +722,7 @@ object IConvertible.ToType(Type conversionType, IFormatProvider provider)
/// </summary>
private
RedisValue
Simplify
()
{
switch
(
Type
)
switch
(
Type
)
{
case
StorageType
.
String
:
string
s
=
(
string
)
_objectOrSentinel
;
...
...
@@ -707,7 +736,7 @@ private RedisValue Simplify()
break
;
case
StorageType
.
Double
:
// is the double actually an integer?
f64
=
OverlappedValueDouble
;
f64
=
OverlappedValueDouble
;
if
(
f64
>=
long
.
MinValue
&&
f64
<=
long
.
MaxValue
&&
(
i64
=
(
long
)
f64
)
==
f64
)
return
i64
;
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment