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
eef7b8d6
Unverified
Commit
eef7b8d6
authored
Mar 18, 2020
by
Marc Gravell
Committed by
GitHub
Mar 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix conversions from null RedisResult (#1392)
parent
503a279c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
19 deletions
+59
-19
RedisResult.cs
src/StackExchange.Redis/RedisResult.cs
+19
-19
Scripting.cs
tests/StackExchange.Redis.Tests/Scripting.cs
+40
-0
No files found.
src/StackExchange.Redis/RedisResult.cs
View file @
eef7b8d6
...
...
@@ -96,12 +96,12 @@ internal static RedisResult TryCreate(PhysicalConnection connection, in RawResul
/// Interprets the result as a <see cref="string"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="string"/>.</param>
public
static
explicit
operator
string
(
RedisResult
result
)
=>
result
.
AsString
();
public
static
explicit
operator
string
(
RedisResult
result
)
=>
result
?
.
AsString
();
/// <summary>
/// Interprets the result as a <see cref="T:byte[]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:byte[]"/>.</param>
public
static
explicit
operator
byte
[](
RedisResult
result
)
=>
result
.
AsByteArray
();
public
static
explicit
operator
byte
[](
RedisResult
result
)
=>
result
?
.
AsByteArray
();
/// <summary>
/// Interprets the result as a <see cref="double"/>.
/// </summary>
...
...
@@ -132,89 +132,89 @@ internal static RedisResult TryCreate(PhysicalConnection connection, in RawResul
/// Interprets the result as a <see cref="RedisValue"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="RedisValue"/>.</param>
public
static
explicit
operator
RedisValue
(
RedisResult
result
)
=>
result
.
AsRedisValue
()
;
public
static
explicit
operator
RedisValue
(
RedisResult
result
)
=>
result
?.
AsRedisValue
()
??
RedisValue
.
Null
;
/// <summary>
/// Interprets the result as a <see cref="RedisKey"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="RedisKey"/>.</param>
public
static
explicit
operator
RedisKey
(
RedisResult
result
)
=>
result
.
AsRedisKey
()
;
public
static
explicit
operator
RedisKey
(
RedisResult
result
)
=>
result
?.
AsRedisKey
()
??
default
;
/// <summary>
/// Interprets the result as a <see cref="T:Nullable{double}"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:Nullable{double}"/>.</param>
public
static
explicit
operator
double
?(
RedisResult
result
)
=>
result
.
AsNullableDouble
();
public
static
explicit
operator
double
?(
RedisResult
result
)
=>
result
?
.
AsNullableDouble
();
/// <summary>
/// Interprets the result as a <see cref="T:Nullable{long}"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:Nullable{long}"/>.</param>
public
static
explicit
operator
long
?(
RedisResult
result
)
=>
result
.
AsNullableInt64
();
public
static
explicit
operator
long
?(
RedisResult
result
)
=>
result
?
.
AsNullableInt64
();
/// <summary>
/// Interprets the result as a <see cref="T:Nullable{ulong}"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:Nullable{ulong}"/>.</param>
[
CLSCompliant
(
false
)]
public
static
explicit
operator
ulong
?(
RedisResult
result
)
=>
result
.
AsNullableUInt64
();
public
static
explicit
operator
ulong
?(
RedisResult
result
)
=>
result
?
.
AsNullableUInt64
();
/// <summary>
/// Interprets the result as a <see cref="T:Nullable{int}"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:Nullable{int}"/>.</param>
public
static
explicit
operator
int
?(
RedisResult
result
)
=>
result
.
AsNullableInt32
();
public
static
explicit
operator
int
?(
RedisResult
result
)
=>
result
?
.
AsNullableInt32
();
/// <summary>
/// Interprets the result as a <see cref="T:Nullable{bool}"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:Nullable{bool}"/>.</param>
public
static
explicit
operator
bool
?(
RedisResult
result
)
=>
result
.
AsNullableBoolean
();
public
static
explicit
operator
bool
?(
RedisResult
result
)
=>
result
?
.
AsNullableBoolean
();
/// <summary>
/// Interprets the result as a <see cref="T:string[]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:string[]"/>.</param>
public
static
explicit
operator
string
[](
RedisResult
result
)
=>
result
.
AsStringArray
();
public
static
explicit
operator
string
[](
RedisResult
result
)
=>
result
?
.
AsStringArray
();
/// <summary>
/// Interprets the result as a <see cref="T:byte[][]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:byte[][]"/>.</param>
public
static
explicit
operator
byte
[][](
RedisResult
result
)
=>
result
.
AsByteArrayArray
();
public
static
explicit
operator
byte
[][](
RedisResult
result
)
=>
result
?
.
AsByteArrayArray
();
/// <summary>
/// Interprets the result as a <see cref="T:double[]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:double[]"/>.</param>
public
static
explicit
operator
double
[](
RedisResult
result
)
=>
result
.
AsDoubleArray
();
public
static
explicit
operator
double
[](
RedisResult
result
)
=>
result
?
.
AsDoubleArray
();
/// <summary>
/// Interprets the result as a <see cref="T:long[]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:long[]"/>.</param>
public
static
explicit
operator
long
[](
RedisResult
result
)
=>
result
.
AsInt64Array
();
public
static
explicit
operator
long
[](
RedisResult
result
)
=>
result
?
.
AsInt64Array
();
/// <summary>
/// Interprets the result as a <see cref="T:ulong[]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:ulong[]"/>.</param>
[
CLSCompliant
(
false
)]
public
static
explicit
operator
ulong
[](
RedisResult
result
)
=>
result
.
AsUInt64Array
();
public
static
explicit
operator
ulong
[](
RedisResult
result
)
=>
result
?
.
AsUInt64Array
();
/// <summary>
/// Interprets the result as a <see cref="T:int[]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:int[]"/>.</param>
public
static
explicit
operator
int
[](
RedisResult
result
)
=>
result
.
AsInt32Array
();
public
static
explicit
operator
int
[](
RedisResult
result
)
=>
result
?
.
AsInt32Array
();
/// <summary>
/// Interprets the result as a <see cref="T:bool[]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:bool[]"/>.</param>
public
static
explicit
operator
bool
[](
RedisResult
result
)
=>
result
.
AsBooleanArray
();
public
static
explicit
operator
bool
[](
RedisResult
result
)
=>
result
?
.
AsBooleanArray
();
/// <summary>
/// Interprets the result as a <see cref="T:RedisValue[]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:RedisValue[]"/>.</param>
public
static
explicit
operator
RedisValue
[](
RedisResult
result
)
=>
result
.
AsRedisValueArray
();
public
static
explicit
operator
RedisValue
[](
RedisResult
result
)
=>
result
?
.
AsRedisValueArray
();
/// <summary>
/// Interprets the result as a <see cref="T:RedisKey[]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:RedisKey[]"/>.</param>
public
static
explicit
operator
RedisKey
[](
RedisResult
result
)
=>
result
.
AsRedisKeyArray
();
public
static
explicit
operator
RedisKey
[](
RedisResult
result
)
=>
result
?
.
AsRedisKeyArray
();
/// <summary>
/// Interprets the result as a <see cref="T:RedisResult[]"/>.
/// </summary>
/// <param name="result">The result to convert to a <see cref="T:RedisResult[]"/>.</param>
public
static
explicit
operator
RedisResult
[](
RedisResult
result
)
=>
result
.
AsRedisResultArray
();
public
static
explicit
operator
RedisResult
[](
RedisResult
result
)
=>
result
?
.
AsRedisResultArray
();
/// <summary>
/// Interprets a multi-bulk result with successive key/name values as a dictionary keyed by name
...
...
tests/StackExchange.Redis.Tests/Scripting.cs
View file @
eef7b8d6
...
...
@@ -941,5 +941,45 @@ public void ScriptWithKeyPrefixCompare()
Assert
.
Equal
(
string
.
Join
(
","
,
viaArr
),
string
.
Join
(
","
,
viaArgs
));
}
}
[
Fact
]
public
void
RedisResultUnderstandsNullArrayArray
()
=>
TestNullArray
(
RedisResult
.
NullArray
);
[
Fact
]
public
void
RedisResultUnderstandsNullArrayNull
()
=>
TestNullArray
(
null
);
static
void
TestNullArray
(
RedisResult
value
)
{
Assert
.
True
(
value
==
null
||
value
.
IsNull
);
Assert
.
Null
((
RedisValue
[])
value
);
Assert
.
Null
((
RedisKey
[])
value
);
Assert
.
Null
((
bool
[])
value
);
Assert
.
Null
((
long
[])
value
);
Assert
.
Null
((
ulong
[])
value
);
Assert
.
Null
((
string
[])
value
);
Assert
.
Null
((
int
[])
value
);
Assert
.
Null
((
double
[])
value
);
Assert
.
Null
((
byte
[][])
value
);
Assert
.
Null
((
RedisResult
[])
value
);
}
[
Fact
]
public
void
RedisResultUnderstandsNullNull
()
=>
TestNullValue
(
null
);
[
Fact
]
public
void
RedisResultUnderstandsNullValue
()
=>
TestNullValue
(
RedisResult
.
Create
(
RedisValue
.
Null
,
ResultType
.
None
));
static
void
TestNullValue
(
RedisResult
value
)
{
Assert
.
True
(
value
==
null
||
value
.
IsNull
);
Assert
.
True
(((
RedisValue
)
value
).
IsNull
);
Assert
.
True
(((
RedisKey
)
value
).
IsNull
);
Assert
.
Null
((
bool
?)
value
);
Assert
.
Null
((
long
?)
value
);
Assert
.
Null
((
ulong
?)
value
);
Assert
.
Null
((
string
)
value
);
Assert
.
Null
((
double
?)
value
);
Assert
.
Null
((
byte
[])
value
);
}
}
}
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