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
76efc9c6
Commit
76efc9c6
authored
Jul 25, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename all the WriteUnified family to help profiling
parent
7cb8f3ce
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
19 deletions
+19
-19
PhysicalConnection.cs
...kExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
+19
-19
No files found.
StackExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
View file @
76efc9c6
...
@@ -571,16 +571,16 @@ internal void Write(RedisKey key)
...
@@ -571,16 +571,16 @@ internal void Write(RedisKey key)
var
val
=
key
.
KeyValue
;
var
val
=
key
.
KeyValue
;
if
(
val
is
string
s
)
if
(
val
is
string
s
)
{
{
WriteUnified
(
_ioPipe
.
Output
,
key
.
KeyPrefix
,
s
,
outEncoder
);
WriteUnified
PrefixedString
(
_ioPipe
.
Output
,
key
.
KeyPrefix
,
s
,
outEncoder
);
}
}
else
else
{
{
WriteUnified
(
_ioPipe
.
Output
,
key
.
KeyPrefix
,
(
byte
[])
val
);
WriteUnified
PrefixedBlob
(
_ioPipe
.
Output
,
key
.
KeyPrefix
,
(
byte
[])
val
);
}
}
}
}
internal
void
Write
(
RedisChannel
channel
)
internal
void
Write
(
RedisChannel
channel
)
=>
WriteUnified
(
_ioPipe
.
Output
,
ChannelPrefix
,
channel
.
Value
);
=>
WriteUnified
PrefixedBlob
(
_ioPipe
.
Output
,
ChannelPrefix
,
channel
.
Value
);
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
internal
void
WriteBulkString
(
RedisValue
value
)
internal
void
WriteBulkString
(
RedisValue
value
)
...
@@ -590,17 +590,17 @@ internal static void WriteBulkString(RedisValue value, PipeWriter output, Encode
...
@@ -590,17 +590,17 @@ internal static void WriteBulkString(RedisValue value, PipeWriter output, Encode
switch
(
value
.
Type
)
switch
(
value
.
Type
)
{
{
case
RedisValue
.
StorageType
.
Null
:
case
RedisValue
.
StorageType
.
Null
:
WriteUnified
(
output
,
(
byte
[])
null
);
WriteUnified
Blob
(
output
,
(
byte
[])
null
);
break
;
break
;
case
RedisValue
.
StorageType
.
Int64
:
case
RedisValue
.
StorageType
.
Int64
:
WriteUnified
(
output
,
(
long
)
value
);
WriteUnified
Int64
(
output
,
(
long
)
value
);
break
;
break
;
case
RedisValue
.
StorageType
.
Double
:
// use string
case
RedisValue
.
StorageType
.
Double
:
// use string
case
RedisValue
.
StorageType
.
String
:
case
RedisValue
.
StorageType
.
String
:
WriteUnified
(
output
,
null
,
(
string
)
value
,
outEncoder
);
WriteUnified
PrefixedString
(
output
,
null
,
(
string
)
value
,
outEncoder
);
break
;
break
;
case
RedisValue
.
StorageType
.
Raw
:
case
RedisValue
.
StorageType
.
Raw
:
WriteUnified
(
output
,
((
ReadOnlyMemory
<
byte
>)
value
).
Span
);
WriteUnified
Span
(
output
,
((
ReadOnlyMemory
<
byte
>)
value
).
Span
);
break
;
break
;
default
:
default
:
throw
new
InvalidOperationException
(
$"Unexpected
{
value
.
Type
}
value: '
{
value
}
'"
);
throw
new
InvalidOperationException
(
$"Unexpected
{
value
.
Type
}
value: '
{
value
}
'"
);
...
@@ -647,7 +647,7 @@ private void WriteHeader(byte[] commandBytes, int arguments)
...
@@ -647,7 +647,7 @@ private void WriteHeader(byte[] commandBytes, int arguments)
int
offset
=
WriteRaw
(
span
,
arguments
+
1
,
offset
:
1
);
int
offset
=
WriteRaw
(
span
,
arguments
+
1
,
offset
:
1
);
offset
=
WriteUnified
(
span
,
commandBytes
,
offset
:
offset
);
offset
=
AppendToSpanBlob
(
span
,
commandBytes
,
offset
:
offset
);
_ioPipe
.
Output
.
Advance
(
offset
);
_ioPipe
.
Output
.
Advance
(
offset
);
}
}
...
@@ -791,7 +791,7 @@ internal WriteResult WakeWriterAndCheckForThrottle()
...
@@ -791,7 +791,7 @@ internal WriteResult WakeWriterAndCheckForThrottle()
private
static
readonly
byte
[]
NullBulkString
=
Encoding
.
ASCII
.
GetBytes
(
"$-1\r\n"
),
EmptyBulkString
=
Encoding
.
ASCII
.
GetBytes
(
"$0\r\n\r\n"
);
private
static
readonly
byte
[]
NullBulkString
=
Encoding
.
ASCII
.
GetBytes
(
"$-1\r\n"
),
EmptyBulkString
=
Encoding
.
ASCII
.
GetBytes
(
"$0\r\n\r\n"
);
private
static
void
WriteUnified
(
PipeWriter
writer
,
byte
[]
value
)
private
static
void
WriteUnified
Blob
(
PipeWriter
writer
,
byte
[]
value
)
{
{
if
(
value
==
null
)
if
(
value
==
null
)
{
{
...
@@ -800,11 +800,11 @@ private static void WriteUnified(PipeWriter writer, byte[] value)
...
@@ -800,11 +800,11 @@ private static void WriteUnified(PipeWriter writer, byte[] value)
}
}
else
else
{
{
WriteUnified
(
writer
,
new
ReadOnlySpan
<
byte
>(
value
));
WriteUnified
Span
(
writer
,
new
ReadOnlySpan
<
byte
>(
value
));
}
}
}
}
private
static
void
WriteUnified
(
PipeWriter
writer
,
ReadOnlySpan
<
byte
>
value
)
private
static
void
WriteUnified
Span
(
PipeWriter
writer
,
ReadOnlySpan
<
byte
>
value
)
{
{
// ${len}\r\n = 3 + MaxInt32TextLen
// ${len}\r\n = 3 + MaxInt32TextLen
// {value}\r\n = 2 + value.Length
// {value}\r\n = 2 + value.Length
...
@@ -819,7 +819,7 @@ private static void WriteUnified(PipeWriter writer, ReadOnlySpan<byte> value)
...
@@ -819,7 +819,7 @@ private static void WriteUnified(PipeWriter writer, ReadOnlySpan<byte> value)
{
{
var
span
=
writer
.
GetSpan
(
5
+
MaxInt32TextLen
+
value
.
Length
);
var
span
=
writer
.
GetSpan
(
5
+
MaxInt32TextLen
+
value
.
Length
);
span
[
0
]
=
(
byte
)
'$'
;
span
[
0
]
=
(
byte
)
'$'
;
int
bytes
=
WriteUnified
(
span
,
value
,
1
);
int
bytes
=
AppendToSpanSpan
(
span
,
value
,
1
);
writer
.
Advance
(
bytes
);
writer
.
Advance
(
bytes
);
}
}
else
else
...
@@ -836,7 +836,7 @@ private static void WriteUnified(PipeWriter writer, ReadOnlySpan<byte> value)
...
@@ -836,7 +836,7 @@ private static void WriteUnified(PipeWriter writer, ReadOnlySpan<byte> value)
}
}
}
}
private
static
int
WriteUnified
(
Span
<
byte
>
span
,
byte
[]
value
,
int
offset
=
0
)
private
static
int
AppendToSpanBlob
(
Span
<
byte
>
span
,
byte
[]
value
,
int
offset
=
0
)
{
{
span
[
offset
++]
=
(
byte
)
'$'
;
span
[
offset
++]
=
(
byte
)
'$'
;
if
(
value
==
null
)
if
(
value
==
null
)
...
@@ -845,12 +845,12 @@ private static int WriteUnified(Span<byte> span, byte[] value, int offset = 0)
...
@@ -845,12 +845,12 @@ private static int WriteUnified(Span<byte> span, byte[] value, int offset = 0)
}
}
else
else
{
{
offset
=
WriteUnified
(
span
,
new
ReadOnlySpan
<
byte
>(
value
),
offset
);
offset
=
AppendToSpanSpan
(
span
,
new
ReadOnlySpan
<
byte
>(
value
),
offset
);
}
}
return
offset
;
return
offset
;
}
}
private
static
int
WriteUnified
(
Span
<
byte
>
span
,
ReadOnlySpan
<
byte
>
value
,
int
offset
=
0
)
private
static
int
AppendToSpanSpan
(
Span
<
byte
>
span
,
ReadOnlySpan
<
byte
>
value
,
int
offset
=
0
)
{
{
offset
=
WriteRaw
(
span
,
value
.
Length
,
offset
:
offset
);
offset
=
WriteRaw
(
span
,
value
.
Length
,
offset
:
offset
);
value
.
CopyTo
(
span
.
Slice
(
offset
,
value
.
Length
));
value
.
CopyTo
(
span
.
Slice
(
offset
,
value
.
Length
));
...
@@ -901,7 +901,7 @@ internal static byte ToHexNibble(int value)
...
@@ -901,7 +901,7 @@ internal static byte ToHexNibble(int value)
return
value
<
10
?
(
byte
)(
'0'
+
value
)
:
(
byte
)(
'a'
-
10
+
value
);
return
value
<
10
?
(
byte
)(
'0'
+
value
)
:
(
byte
)(
'a'
-
10
+
value
);
}
}
internal
static
void
WriteUnified
(
PipeWriter
writer
,
byte
[]
prefix
,
string
value
,
Encoder
outEncoder
)
internal
static
void
WriteUnified
PrefixedString
(
PipeWriter
writer
,
byte
[]
prefix
,
string
value
,
Encoder
outEncoder
)
{
{
if
(
value
==
null
)
if
(
value
==
null
)
{
{
...
@@ -990,14 +990,14 @@ unsafe static internal void WriteRaw(PipeWriter writer, string value, int expect
...
@@ -990,14 +990,14 @@ unsafe static internal void WriteRaw(PipeWriter writer, string value, int expect
private
readonly
Encoder
outEncoder
=
Encoding
.
UTF8
.
GetEncoder
();
private
readonly
Encoder
outEncoder
=
Encoding
.
UTF8
.
GetEncoder
();
private
static
void
WriteUnified
(
PipeWriter
writer
,
byte
[]
prefix
,
byte
[]
value
)
private
static
void
WriteUnified
PrefixedBlob
(
PipeWriter
writer
,
byte
[]
prefix
,
byte
[]
value
)
{
{
// ${total-len}\r\n
// ${total-len}\r\n
// {prefix}{value}\r\n
// {prefix}{value}\r\n
if
(
prefix
==
null
||
prefix
.
Length
==
0
||
value
==
null
)
if
(
prefix
==
null
||
prefix
.
Length
==
0
||
value
==
null
)
{
// if no prefix, just use the non-prefixed version;
{
// if no prefix, just use the non-prefixed version;
// even if prefixed, a null value writes as null, so can use the non-prefixed version
// even if prefixed, a null value writes as null, so can use the non-prefixed version
WriteUnified
(
writer
,
value
);
WriteUnified
Blob
(
writer
,
value
);
}
}
else
else
{
{
...
@@ -1015,7 +1015,7 @@ private static void WriteUnified(PipeWriter writer, byte[] prefix, byte[] value)
...
@@ -1015,7 +1015,7 @@ private static void WriteUnified(PipeWriter writer, byte[] prefix, byte[] value)
}
}
}
}
private
static
void
WriteUnified
(
PipeWriter
writer
,
long
value
)
private
static
void
WriteUnified
Int64
(
PipeWriter
writer
,
long
value
)
{
{
// note from specification: A client sends to the Redis server a RESP Array consisting of just Bulk Strings.
// note from specification: A client sends to the Redis server a RESP Array consisting of just Bulk Strings.
// (i.e. we can't just send ":123\r\n", we need to send "$3\r\n123\r\n"
// (i.e. we can't just send ":123\r\n", we need to send "$3\r\n123\r\n"
...
...
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