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
b0637c6f
Commit
b0637c6f
authored
Jun 26, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix null handling error
parent
d1c358c5
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
180 additions
and
15 deletions
+180
-15
SO24807536.cs
StackExchange.Redis.Tests/Issues/SO24807536.cs
+4
-1
RawResultTests.cs
StackExchange.Redis.Tests/RawResultTests.cs
+61
-0
StackExchange.Redis.sln
StackExchange.Redis.sln
+21
-0
StackExchange.Redis.csproj
StackExchange.Redis/StackExchange.Redis.csproj
+7
-1
PhysicalConnection.cs
...kExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
+2
-3
RawResult.cs
StackExchange.Redis/StackExchange/Redis/RawResult.cs
+10
-10
Program.cs
TestConsole/Program.cs
+56
-0
TestConsole.csproj
TestConsole/TestConsole.csproj
+19
-0
No files found.
StackExchange.Redis.Tests/Issues/SO24807536.cs
View file @
b0637c6f
...
...
@@ -37,9 +37,12 @@ public void Exec()
keyExists
=
cache
.
KeyExists
(
key
);
ttl
=
cache
.
KeyTimeToLive
(
key
);
fullWait
=
cache
.
HashGetAsync
(
key
,
"full"
,
flags
:
CommandFlags
.
None
);
Assert
.
False
(
keyExists
);
Assert
.
Null
(
ttl
);
Assert
.
Null
((
string
)
fullWait
.
Result
);
var
r
=
fullWait
.
Result
;
Assert
.
True
(
r
.
IsNull
);
Assert
.
Null
((
string
)
r
);
}
}
}
...
...
StackExchange.Redis.Tests/RawResultTests.cs
0 → 100644
View file @
b0637c6f
using
System.Buffers
;
using
Xunit
;
namespace
StackExchange.Redis.Tests
{
public
class
RawResultTests
{
[
Fact
]
public
void
NullWorks
()
{
var
result
=
new
RawResult
(
ResultType
.
BulkString
,
ReadOnlySequence
<
byte
>.
Empty
,
true
);
Assert
.
Equal
(
ResultType
.
BulkString
,
result
.
Type
);
Assert
.
True
(
result
.
IsNull
);
var
value
=
result
.
AsRedisValue
();
Assert
.
True
(
value
.
IsNull
);
string
s
=
(
string
)
value
;
Assert
.
Null
(
s
);
byte
[]
arr
=
(
byte
[])
value
;
Assert
.
Null
(
arr
);
}
[
Fact
]
public
void
DefaultWorks
()
{
var
result
=
default
(
RawResult
);
Assert
.
Equal
(
ResultType
.
None
,
result
.
Type
);
Assert
.
True
(
result
.
IsNull
);
var
value
=
result
.
AsRedisValue
();
Assert
.
True
(
value
.
IsNull
);
var
s
=
(
string
)
value
;
Assert
.
Null
(
s
);
var
arr
=
(
byte
[])
value
;
Assert
.
Null
(
arr
);
}
[
Fact
]
public
void
NilWorks
()
{
var
result
=
RawResult
.
Nil
;
Assert
.
Equal
(
ResultType
.
None
,
result
.
Type
);
Assert
.
True
(
result
.
IsNull
);
var
value
=
result
.
AsRedisValue
();
Assert
.
True
(
value
.
IsNull
);
var
s
=
(
string
)
value
;
Assert
.
Null
(
s
);
var
arr
=
(
byte
[])
value
;
Assert
.
Null
(
arr
);
}
}
}
StackExchange.Redis.sln
View file @
b0637c6f
...
...
@@ -8,6 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
appveyor.yml = appveyor.yml
Directory.build.props = Directory.build.props
global.json = global.json
NuGet.Config = NuGet.Config
version.json = version.json
EndProjectSection
...
...
@@ -66,6 +67,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Basic", "Basic", "{38BDEEED
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicTestBaseline", "BasicTestBaseline\BasicTestBaseline.csproj", "{8FDB623D-779B-4A84-BC6B-75106E41D8A4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pipelines.Sockets.Unofficial", "..\Pipelines.Sockets.Unofficial\src\Pipelines.Sockets.Unofficial\Pipelines.Sockets.Unofficial.csproj", "{6BE847CC-5615-4C72-A304-3DB29725FC76}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsole", "TestConsole\TestConsole.csproj", "{651FDB97-9DE3-4BD9-9A05-827AF8F1A94A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -122,6 +127,22 @@ Global
{8FDB623D-779B-4A84-BC6B-75106E41D8A4}.Release|Any CPU.Build.0 = Release|Any CPU
{8FDB623D-779B-4A84-BC6B-75106E41D8A4}.Verbose|Any CPU.ActiveCfg = Release|Any CPU
{8FDB623D-779B-4A84-BC6B-75106E41D8A4}.Verbose|Any CPU.Build.0 = Release|Any CPU
{6BE847CC-5615-4C72-A304-3DB29725FC76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BE847CC-5615-4C72-A304-3DB29725FC76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BE847CC-5615-4C72-A304-3DB29725FC76}.Log Output|Any CPU.ActiveCfg = Debug|Any CPU
{6BE847CC-5615-4C72-A304-3DB29725FC76}.Log Output|Any CPU.Build.0 = Debug|Any CPU
{6BE847CC-5615-4C72-A304-3DB29725FC76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BE847CC-5615-4C72-A304-3DB29725FC76}.Release|Any CPU.Build.0 = Release|Any CPU
{6BE847CC-5615-4C72-A304-3DB29725FC76}.Verbose|Any CPU.ActiveCfg = Debug|Any CPU
{6BE847CC-5615-4C72-A304-3DB29725FC76}.Verbose|Any CPU.Build.0 = Debug|Any CPU
{651FDB97-9DE3-4BD9-9A05-827AF8F1A94A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{651FDB97-9DE3-4BD9-9A05-827AF8F1A94A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{651FDB97-9DE3-4BD9-9A05-827AF8F1A94A}.Log Output|Any CPU.ActiveCfg = Debug|Any CPU
{651FDB97-9DE3-4BD9-9A05-827AF8F1A94A}.Log Output|Any CPU.Build.0 = Debug|Any CPU
{651FDB97-9DE3-4BD9-9A05-827AF8F1A94A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{651FDB97-9DE3-4BD9-9A05-827AF8F1A94A}.Release|Any CPU.Build.0 = Release|Any CPU
{651FDB97-9DE3-4BD9-9A05-827AF8F1A94A}.Verbose|Any CPU.ActiveCfg = Debug|Any CPU
{651FDB97-9DE3-4BD9-9A05-827AF8F1A94A}.Verbose|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
StackExchange.Redis/StackExchange.Redis.csproj
View file @
b0637c6f
...
...
@@ -16,7 +16,13 @@
<ItemGroup>
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.IO.Pipelines" Version="$(CoreFxVersion)" />
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="0.2.1-alpha.43" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="$(CoreFxVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(Computername)'=='OCHO'">
<ProjectReference Include="..\..\Pipelines.Sockets.Unofficial\src\Pipelines.Sockets.Unofficial\Pipelines.Sockets.Unofficial.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(Computername)'!='OCHO'">
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="0.2.1-alpha.45" />
</ItemGroup>
</Project>
\ No newline at end of file
StackExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
View file @
b0637c6f
...
...
@@ -1003,9 +1003,8 @@ void ISocketCallback.OnHeartbeat()
}
var
buffer
=
readResult
.
Buffer
;
var
s
=
new
RawResult
(
ResultType
.
BulkString
,
buffer
,
false
).
GetString
().
Replace
(
"\r"
,
"\\r"
).
Replace
(
"\n"
,
"\\n"
);
int
handled
=
ProcessBuffer
(
ref
buffer
);
// updates buffer.Start
allowSyncRead
=
handled
!=
0
;
Multiplexer
.
Trace
(
$"Processed
{
handled
}
messages"
,
physicalName
);
...
...
@@ -1024,7 +1023,7 @@ void ISocketCallback.OnHeartbeat()
private
int
ProcessBuffer
(
ref
ReadOnlySequence
<
byte
>
buffer
)
{
int
messageCount
=
0
;
while
(!
buffer
.
IsEmpty
)
{
var
reader
=
new
BufferReader
(
buffer
);
...
...
StackExchange.Redis/StackExchange/Redis/RawResult.cs
View file @
b0637c6f
...
...
@@ -7,15 +7,16 @@ namespace StackExchange.Redis
internal
readonly
struct
RawResult
{
internal
static
readonly
RawResult
NullMultiBulk
=
new
RawResult
((
RawResult
[])
null
);
internal
static
readonly
RawResult
EmptyMultiBulk
=
new
RawResult
(
new
RawResult
[
0
]
);
internal
static
readonly
RawResult
Nil
=
new
RawResult
()
;
internal
static
readonly
RawResult
EmptyMultiBulk
=
new
RawResult
(
Array
.
Empty
<
RawResult
>()
);
internal
static
readonly
RawResult
Nil
=
default
;
private
readonly
ReadOnlySequence
<
byte
>
_payload
;
private
readonly
RawResult
[]
_subArray
;
private
readonly
ResultType
_type
;
const
ResultType
NullResultTypeBit
=
unchecked
((
ResultType
)(
1
<<
31
));
const
ResultType
NonNullFlag
=
(
ResultType
)
128
;
public
RawResult
(
ResultType
resultType
,
ReadOnlySequence
<
byte
>
payload
,
bool
isNull
)
{
switch
(
resultType
)
...
...
@@ -28,7 +29,7 @@ public RawResult(ResultType resultType, ReadOnlySequence<byte> payload, bool isN
default
:
throw
new
ArgumentOutOfRangeException
(
nameof
(
resultType
));
}
if
(
isNull
)
resultType
|=
NullResultTypeBit
;
if
(
!
isNull
)
resultType
|=
NonNullFlag
;
_type
=
resultType
;
_payload
=
payload
;
_subArray
=
default
;
...
...
@@ -37,19 +38,17 @@ public RawResult(ResultType resultType, ReadOnlySequence<byte> payload, bool isN
public
RawResult
(
RawResult
[]
arr
)
{
_type
=
ResultType
.
MultiBulk
;
if
(
arr
==
null
)
_type
|=
NullResultTypeBit
;
if
(
arr
!=
null
)
_type
|=
NonNullFlag
;
_payload
=
default
;
_subArray
=
arr
;
}
public
bool
HasValue
=>
Type
!=
ResultType
.
None
;
public
bool
IsError
=>
Type
==
ResultType
.
Error
;
public
ResultType
Type
=>
_type
&
~
NullResultTypeBit
;
internal
bool
IsNull
=>
(
_type
&
NullResultTypeBit
)
!=
0
;
public
ResultType
Type
=>
_type
&
~
NonNullFlag
;
internal
bool
IsNull
=>
(
_type
&
NonNullFlag
)
==
0
;
public
bool
HasValue
=>
Type
!=
ResultType
.
None
;
public
override
string
ToString
()
{
if
(
IsNull
)
return
"(null)"
;
...
...
@@ -105,6 +104,7 @@ internal RedisKey AsRedisKey()
internal
RedisValue
AsRedisValue
()
{
if
(
IsNull
)
return
RedisValue
.
Null
;
switch
(
Type
)
{
case
ResultType
.
Integer
:
...
...
TestConsole/Program.cs
0 → 100644
View file @
b0637c6f
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
StackExchange.Redis
;
class
Program
{
static
int
Main
()
{
var
s
=
new
StringWriter
();
try
{
#if DEBUG
Pipelines
.
Sockets
.
Unofficial
.
DebugCounters
.
SetLog
(
Console
.
Out
);
#endif
// it is sometimes hard to get the debugger to play nicely with benchmarkdotnet/xunit attached,
// so this is just a *trivial* exe
var
config
=
new
ConfigurationOptions
{
EndPoints
=
{
"127.0.0.1"
},
//TieBreaker = "",
//CommandMap = CommandMap.Create(new Dictionary<string, string>
//{
// ["SUBSCRIBE"] = null,
// ["PSUBSCRIBE"] = null,
//})
};
using
(
var
conn
=
ConnectionMultiplexer
.
Connect
(
config
,
log
:
s
))
{
Console
.
WriteLine
(
"Connected"
);
var
db
=
conn
.
GetDatabase
();
db
.
StringSet
(
"abc"
,
"def"
);
var
x
=
db
.
StringGet
(
"abc"
);
Console
.
WriteLine
(
x
);
//for (int i = 0; i < 10; i++)
//{
// Console.WriteLine($"Ping {i}");
// db.Ping();
//}
}
Console
.
WriteLine
(
"Clean exit"
);
return
0
;
}
catch
(
Exception
ex
)
{
Console
.
Error
.
WriteLine
(
ex
);
return
-
1
;
}
finally
{
Console
.
WriteLine
();
Console
.
WriteLine
(
s
);
}
}
}
TestConsole/TestConsole.csproj
0 → 100644
View file @
b0637c6f
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;net462</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\StackExchange.Redis\StackExchange.Redis.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(Computername)'=='OCHO'">
<ProjectReference Include="..\..\Pipelines.Sockets.Unofficial\src\Pipelines.Sockets.Unofficial\Pipelines.Sockets.Unofficial.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(Computername)'!='OCHO'">
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="0.2.1-alpha.45" />
</ItemGroup>
</Project>
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