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
93ab472f
Commit
93ab472f
authored
Sep 30, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize pub/sub for short (<=23 bytes) channel keys
parent
c1fd3b0b
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
182 additions
and
46 deletions
+182
-46
CommandBytes.cs
src/StackExchange.Redis/CommandBytes.cs
+19
-5
RedisRequest.cs
toys/StackExchange.Redis.Server/RedisRequest.cs
+3
-3
RedisServer.cs
toys/StackExchange.Redis.Server/RedisServer.cs
+160
-38
No files found.
src/StackExchange.Redis/CommandBytes.cs
View file @
93ab472f
...
@@ -25,7 +25,7 @@ internal unsafe static CommandBytes TrimToFit(string value)
...
@@ -25,7 +25,7 @@ internal unsafe static CommandBytes TrimToFit(string value)
}
}
}
}
// Uses [
n=4
] x UInt64 values to store a command payload,
// Uses [
ChunkLength
] x UInt64 values to store a command payload,
// allowing allocation free storage and efficient
// allowing allocation free storage and efficient
// equality tests. If you're glancing at this and thinking
// equality tests. If you're glancing at this and thinking
// "that's what fixed buffers are for", please see:
// "that's what fixed buffers are for", please see:
...
@@ -114,7 +114,7 @@ public unsafe CommandBytes(string value)
...
@@ -114,7 +114,7 @@ public unsafe CommandBytes(string value)
}
}
}
}
public
unsafe
CommandBytes
(
ReadOnlySpan
<
byte
>
value
)
public
unsafe
CommandBytes
(
ReadOnlySpan
<
byte
>
value
,
bool
caseInsensitive
=
true
)
{
{
if
(
value
.
Length
>
MaxLength
)
throw
new
ArgumentOutOfRangeException
(
"Maximum command length exceeed: "
+
value
.
Length
+
" bytes"
);
if
(
value
.
Length
>
MaxLength
)
throw
new
ArgumentOutOfRangeException
(
"Maximum command length exceeed: "
+
value
.
Length
+
" bytes"
);
_0
=
_1
=
_2
=
0L
;
_0
=
_1
=
_2
=
0L
;
...
@@ -122,10 +122,17 @@ public unsafe CommandBytes(ReadOnlySpan<byte> value)
...
@@ -122,10 +122,17 @@ public unsafe CommandBytes(ReadOnlySpan<byte> value)
{
{
byte
*
bPtr
=
(
byte
*)
uPtr
;
byte
*
bPtr
=
(
byte
*)
uPtr
;
value
.
CopyTo
(
new
Span
<
byte
>(
bPtr
+
1
,
value
.
Length
));
value
.
CopyTo
(
new
Span
<
byte
>(
bPtr
+
1
,
value
.
Length
));
*
bPtr
=
(
byte
)
UpperCasify
(
value
.
Length
,
bPtr
+
1
);
if
(
caseInsensitive
)
{
*
bPtr
=
(
byte
)
UpperCasify
(
value
.
Length
,
bPtr
+
1
);
}
else
{
*
bPtr
=
(
byte
)
value
.
Length
;
}
}
}
}
}
public
unsafe
CommandBytes
(
ReadOnlySequence
<
byte
>
value
)
public
unsafe
CommandBytes
(
ReadOnlySequence
<
byte
>
value
,
bool
caseInsensitive
=
true
)
{
{
if
(
value
.
Length
>
MaxLength
)
throw
new
ArgumentOutOfRangeException
(
"Maximum command length exceeed"
);
if
(
value
.
Length
>
MaxLength
)
throw
new
ArgumentOutOfRangeException
(
"Maximum command length exceeed"
);
int
len
=
unchecked
((
int
)
value
.
Length
);
int
len
=
unchecked
((
int
)
value
.
Length
);
...
@@ -147,7 +154,14 @@ public unsafe CommandBytes(ReadOnlySequence<byte> value)
...
@@ -147,7 +154,14 @@ public unsafe CommandBytes(ReadOnlySequence<byte> value)
target
=
target
.
Slice
(
segment
.
Length
);
target
=
target
.
Slice
(
segment
.
Length
);
}
}
}
}
*
bPtr
=
(
byte
)
UpperCasify
(
len
,
bPtr
+
1
);
if
(
caseInsensitive
)
{
*
bPtr
=
(
byte
)
UpperCasify
(
len
,
bPtr
+
1
);
}
else
{
*
bPtr
=
(
byte
)
len
;
}
}
}
}
}
private
unsafe
int
UpperCasify
(
int
len
,
byte
*
bPtr
)
private
unsafe
int
UpperCasify
(
int
len
,
byte
*
bPtr
)
...
...
toys/StackExchange.Redis.Server/RedisRequest.cs
View file @
93ab472f
...
@@ -49,16 +49,16 @@ public int GetInt32(int index)
...
@@ -49,16 +49,16 @@ public int GetInt32(int index)
public
RedisChannel
GetChannel
(
int
index
,
RedisChannel
.
PatternMode
mode
)
public
RedisChannel
GetChannel
(
int
index
,
RedisChannel
.
PatternMode
mode
)
=>
_inner
[
index
].
AsRedisChannel
(
null
,
mode
);
=>
_inner
[
index
].
AsRedisChannel
(
null
,
mode
);
internal
bool
TryGetCommandBytes
(
int
i
,
out
CommandBytes
command
)
internal
bool
TryGetCommandBytes
(
int
i
ndex
,
out
CommandBytes
command
,
bool
caseInsensitive
=
true
)
{
{
var
payload
=
_inner
[
i
].
Payload
;
var
payload
=
_inner
[
i
ndex
].
Payload
;
if
(
payload
.
Length
>
CommandBytes
.
MaxLength
)
if
(
payload
.
Length
>
CommandBytes
.
MaxLength
)
{
{
command
=
default
;
command
=
default
;
return
false
;
return
false
;
}
}
command
=
payload
.
IsEmpty
?
default
:
new
CommandBytes
(
payload
);
command
=
payload
.
IsEmpty
?
default
:
new
CommandBytes
(
payload
,
caseInsensitive
);
return
true
;
return
true
;
}
}
}
}
...
...
toys/StackExchange.Redis.Server/RedisServer.cs
View file @
93ab472f
This diff is collapsed.
Click to expand it.
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