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
743d3ca8
Commit
743d3ca8
authored
Nov 30, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make use of "in" for larger readonly structs on non-public APIs
parent
7de44835
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
124 additions
and
75 deletions
+124
-75
ChannelMessageQueue.cs
src/StackExchange.Redis/ChannelMessageQueue.cs
+4
-2
CommandBytes.cs
src/StackExchange.Redis/CommandBytes.cs
+9
-2
ConnectionMultiplexer.cs
src/StackExchange.Redis/ConnectionMultiplexer.cs
+1
-1
ExceptionFactory.cs
src/StackExchange.Redis/ExceptionFactory.cs
+2
-0
GeoEntry.cs
src/StackExchange.Redis/GeoEntry.cs
+13
-1
Message.cs
src/StackExchange.Redis/Message.cs
+42
-42
PhysicalConnection.cs
src/StackExchange.Redis/PhysicalConnection.cs
+10
-8
RawResult.cs
src/StackExchange.Redis/RawResult.cs
+4
-4
RedisChannel.cs
src/StackExchange.Redis/RedisChannel.cs
+24
-0
RedisDatabase.cs
src/StackExchange.Redis/RedisDatabase.cs
+4
-4
RedisSubscriber.cs
src/StackExchange.Redis/RedisSubscriber.cs
+9
-9
RespServer.cs
toys/StackExchange.Redis.Server/RespServer.cs
+2
-2
No files found.
src/StackExchange.Redis/ChannelMessageQueue.cs
View file @
743d3ca8
...
...
@@ -28,7 +28,7 @@ namespace StackExchange.Redis
/// <param name="obj">The <see cref="object"/> to compare.</param>
public
override
bool
Equals
(
object
obj
)
=>
obj
is
ChannelMessage
cm
&&
cm
.
Channel
==
Channel
&&
cm
.
Message
==
Message
;
internal
ChannelMessage
(
ChannelMessageQueue
queue
,
RedisChannel
channel
,
RedisValue
value
)
internal
ChannelMessage
(
ChannelMessageQueue
queue
,
in
RedisChannel
channel
,
in
RedisValue
value
)
{
_queue
=
queue
;
Channel
=
channel
;
...
...
@@ -73,7 +73,7 @@ public sealed class ChannelMessageQueue
/// </summary>
public
Task
Completion
=>
_queue
.
Reader
.
Completion
;
internal
ChannelMessageQueue
(
RedisChannel
redisChannel
,
RedisSubscriber
parent
)
internal
ChannelMessageQueue
(
in
RedisChannel
redisChannel
,
RedisSubscriber
parent
)
{
Channel
=
redisChannel
;
_parent
=
parent
;
...
...
@@ -89,7 +89,9 @@ internal ChannelMessageQueue(RedisChannel redisChannel, RedisSubscriber parent)
internal
void
Subscribe
(
CommandFlags
flags
)
=>
_parent
.
Subscribe
(
Channel
,
HandleMessage
,
flags
);
internal
Task
SubscribeAsync
(
CommandFlags
flags
)
=>
_parent
.
SubscribeAsync
(
Channel
,
HandleMessage
,
flags
);
#pragma warning disable RCS1231 // Make parameter ref read-only. - uses as a delegate for Action<RedisChannel, RedisValue>
private
void
HandleMessage
(
RedisChannel
channel
,
RedisValue
value
)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{
var
writer
=
_queue
.
Writer
;
if
(
channel
.
IsNull
&&
value
.
IsNull
)
// see ForSyncShutdown
...
...
src/StackExchange.Redis/CommandBytes.cs
View file @
743d3ca8
...
...
@@ -46,7 +46,9 @@ public override int GetHashCode()
}
public
override
bool
Equals
(
object
obj
)
=>
obj
is
CommandBytes
cb
&&
Equals
(
cb
);
public
bool
Equals
(
CommandBytes
other
)
=>
_0
==
other
.
_0
&&
_1
==
other
.
_1
&&
_2
==
other
.
_2
;
bool
IEquatable
<
CommandBytes
>.
Equals
(
CommandBytes
other
)
=>
_0
==
other
.
_0
&&
_1
==
other
.
_1
&&
_2
==
other
.
_2
;
public
bool
Equals
(
in
CommandBytes
other
)
=>
_0
==
other
.
_0
&&
_1
==
other
.
_1
&&
_2
==
other
.
_2
;
// note: don't add == operators; with the implicit op above, that invalidates "==null" compiler checks (which should report a failure!)
...
...
@@ -74,7 +76,9 @@ public unsafe int Length
public
bool
IsEmpty
=>
_0
==
0L
;
// cheap way of checking zero length
#pragma warning disable RCS1231 // Make parameter ref read-only. - spans are tiny!
public
unsafe
void
CopyTo
(
Span
<
byte
>
target
)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{
fixed
(
ulong
*
uPtr
=
&
_0
)
{
...
...
@@ -114,7 +118,9 @@ public unsafe CommandBytes(string value)
}
}
#pragma warning disable RCS1231 // Make parameter ref read-only. - spans are tiny!
public
unsafe
CommandBytes
(
ReadOnlySpan
<
byte
>
value
)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{
if
(
value
.
Length
>
MaxLength
)
throw
new
ArgumentOutOfRangeException
(
"Maximum command length exceeed: "
+
value
.
Length
+
" bytes"
);
_0
=
_1
=
_2
=
0L
;
...
...
@@ -125,7 +131,8 @@ public unsafe CommandBytes(ReadOnlySpan<byte> value)
*
bPtr
=
(
byte
)
UpperCasify
(
value
.
Length
,
bPtr
+
1
);
}
}
public
unsafe
CommandBytes
(
ReadOnlySequence
<
byte
>
value
)
public
unsafe
CommandBytes
(
in
ReadOnlySequence
<
byte
>
value
)
{
if
(
value
.
Length
>
MaxLength
)
throw
new
ArgumentOutOfRangeException
(
"Maximum command length exceeed"
);
int
len
=
unchecked
((
int
)
value
.
Length
);
...
...
src/StackExchange.Redis/ConnectionMultiplexer.cs
View file @
743d3ca8
...
...
@@ -1896,7 +1896,7 @@ internal ServerEndPoint SelectServer(Message message)
return
ServerSelectionStrategy
.
Select
(
message
);
}
internal
ServerEndPoint
SelectServer
(
RedisCommand
command
,
CommandFlags
flags
,
RedisKey
key
)
internal
ServerEndPoint
SelectServer
(
RedisCommand
command
,
CommandFlags
flags
,
in
RedisKey
key
)
{
return
ServerSelectionStrategy
.
Select
(
command
,
key
,
flags
);
}
...
...
src/StackExchange.Redis/ExceptionFactory.cs
View file @
743d3ca8
...
...
@@ -125,7 +125,9 @@ internal static Exception NoConnectionAvailable(bool includeDetail, bool include
return
ex
;
}
#pragma warning disable RCS1231 // Make parameter ref read-only. - spans are tiny!
internal
static
Exception
PopulateInnerExceptions
(
ReadOnlySpan
<
ServerEndPoint
>
serverSnapshot
)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{
var
innerExceptions
=
new
List
<
Exception
>();
...
...
src/StackExchange.Redis/GeoEntry.cs
View file @
743d3ca8
...
...
@@ -68,7 +68,7 @@ public enum GeoRadiusOptions
/// <param name="distance">Tthe distance from the result.</param>
/// <param name="hash">The hash of the result.</param>
/// <param name="position">The geo position of the result.</param>
internal
GeoRadiusResult
(
RedisValue
member
,
double
?
distance
,
long
?
hash
,
GeoPosition
?
position
)
internal
GeoRadiusResult
(
in
RedisValue
member
,
double
?
distance
,
long
?
hash
,
GeoPosition
?
position
)
{
Member
=
member
;
Distance
=
distance
;
...
...
@@ -140,21 +140,27 @@ public GeoPosition(double longitude, double latitude)
/// Compares two values for equality
/// </summary>
/// <param name="other">The <see cref="GeoPosition"/> to compare to.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
bool
Equals
(
GeoPosition
other
)
=>
this
==
other
;
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Compares two values for equality
/// </summary>
/// <param name="x">The first position to compare.</param>
/// <param name="y">The second position to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
==(
GeoPosition
x
,
GeoPosition
y
)
=>
x
.
Longitude
==
y
.
Longitude
&&
x
.
Latitude
==
y
.
Latitude
;
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Compares two values for non-equality
/// </summary>
/// <param name="x">The first position to compare.</param>
/// <param name="y">The second position to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
!=(
GeoPosition
x
,
GeoPosition
y
)
=>
x
.
Longitude
!=
y
.
Longitude
||
x
.
Latitude
!=
y
.
Latitude
;
#pragma warning restore RCS1231 // Make parameter ref read-only.
}
/// <summary>
...
...
@@ -179,7 +185,9 @@ public GeoPosition(double longitude, double latitude)
/// <param name="longitude">The longitude position to use.</param>
/// <param name="latitude">The latitude position to use.</param>
/// <param name="member">The value to store for this position.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
GeoEntry
(
double
longitude
,
double
latitude
,
RedisValue
member
)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{
Member
=
member
;
Position
=
new
GeoPosition
(
longitude
,
latitude
);
...
...
@@ -222,13 +230,17 @@ public GeoEntry(double longitude, double latitude, RedisValue member)
/// </summary>
/// <param name="x">The first entry to compare.</param>
/// <param name="y">The second entry to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
==(
GeoEntry
x
,
GeoEntry
y
)
=>
x
.
Position
==
y
.
Position
&&
x
.
Member
==
y
.
Member
;
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Compares two values for non-equality
/// </summary>
/// <param name="x">The first entry to compare.</param>
/// <param name="y">The second entry to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
!=(
GeoEntry
x
,
GeoEntry
y
)
=>
x
.
Position
!=
y
.
Position
||
x
.
Member
!=
y
.
Member
;
#pragma warning restore RCS1231 // Make parameter ref read-only.
}
}
src/StackExchange.Redis/Message.cs
View file @
743d3ca8
...
...
@@ -217,62 +217,62 @@ public static Message Create(int db, CommandFlags flags, RedisCommand command)
return
new
CommandMessage
(
db
,
flags
,
command
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
)
{
return
new
CommandKeyMessage
(
db
,
flags
,
command
,
key
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key0
,
RedisKey
key1
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key0
,
in
RedisKey
key1
)
{
return
new
CommandKeyKeyMessage
(
db
,
flags
,
command
,
key0
,
key1
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key0
,
RedisKey
key1
,
RedisValue
value
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key0
,
in
RedisKey
key1
,
in
RedisValue
value
)
{
return
new
CommandKeyKeyValueMessage
(
db
,
flags
,
command
,
key0
,
key1
,
value
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key0
,
RedisKey
key1
,
RedisKey
key2
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key0
,
in
RedisKey
key1
,
in
RedisKey
key2
)
{
return
new
CommandKeyKeyKeyMessage
(
db
,
flags
,
command
,
key0
,
key1
,
key2
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value
)
{
return
new
CommandValueMessage
(
db
,
flags
,
command
,
value
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisValue
value
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
in
RedisValue
value
)
{
return
new
CommandKeyValueMessage
(
db
,
flags
,
command
,
key
,
value
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisChannel
channel
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisChannel
channel
)
{
return
new
CommandChannelMessage
(
db
,
flags
,
command
,
channel
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisChannel
channel
,
RedisValue
value
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisChannel
channel
,
in
RedisValue
value
)
{
return
new
CommandChannelValueMessage
(
db
,
flags
,
command
,
channel
,
value
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value
,
RedisChannel
channel
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value
,
in
RedisChannel
channel
)
{
return
new
CommandValueChannelMessage
(
db
,
flags
,
command
,
value
,
channel
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisValue
value0
,
RedisValue
value1
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
in
RedisValue
value0
,
in
RedisValue
value1
)
{
return
new
CommandKeyValueValueMessage
(
db
,
flags
,
command
,
key
,
value0
,
value1
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisValue
value0
,
RedisValue
value1
,
RedisValue
value2
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
in
RedisValue
value0
,
in
RedisValue
value1
,
in
RedisValue
value2
)
{
return
new
CommandKeyValueValueValueMessage
(
db
,
flags
,
command
,
key
,
value0
,
value1
,
value2
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
GeoEntry
[]
values
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
GeoEntry
[]
values
)
{
if
(
values
==
null
)
throw
new
ArgumentNullException
(
nameof
(
values
));
if
(
values
.
Length
==
0
)
...
...
@@ -295,27 +295,27 @@ public static Message Create(int db, CommandFlags flags, RedisCommand command, R
return
new
CommandKeyValuesMessage
(
db
,
flags
,
command
,
key
,
arr
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisValue
value0
,
RedisValue
value1
,
RedisValue
value2
,
RedisValue
value3
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
in
RedisValue
value0
,
in
RedisValue
value1
,
in
RedisValue
value2
,
in
RedisValue
value3
)
{
return
new
CommandKeyValueValueValueValueMessage
(
db
,
flags
,
command
,
key
,
value0
,
value1
,
value2
,
value3
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value0
,
RedisValue
value1
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value0
,
in
RedisValue
value1
)
{
return
new
CommandValueValueMessage
(
db
,
flags
,
command
,
value0
,
value1
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value
,
RedisKey
key
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value
,
in
RedisKey
key
)
{
return
new
CommandValueKeyMessage
(
db
,
flags
,
command
,
value
,
key
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value0
,
RedisValue
value1
,
RedisValue
value2
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value0
,
in
RedisValue
value1
,
in
RedisValue
value2
)
{
return
new
CommandValueValueValueMessage
(
db
,
flags
,
command
,
value0
,
value1
,
value2
);
}
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value0
,
RedisValue
value1
,
RedisValue
value2
,
RedisValue
value3
,
RedisValue
value4
)
public
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value0
,
in
RedisValue
value1
,
in
RedisValue
value2
,
in
RedisValue
value3
,
in
RedisValue
value4
)
{
return
new
CommandValueValueValueValueValueMessage
(
db
,
flags
,
command
,
value0
,
value1
,
value2
,
value3
,
value4
);
}
...
...
@@ -467,7 +467,7 @@ public bool TryComplete(bool isAsync)
}
}
internal
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisKey
[]
keys
)
internal
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
RedisKey
[]
keys
)
{
switch
(
keys
.
Length
)
{
...
...
@@ -504,7 +504,7 @@ internal static Message Create(int db, CommandFlags flags, RedisCommand command,
}
}
internal
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisValue
[]
values
)
internal
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
RedisValue
[]
values
)
{
if
(
values
==
null
)
throw
new
ArgumentNullException
(
nameof
(
values
));
switch
(
values
.
Length
)
...
...
@@ -518,7 +518,7 @@ internal static Message Create(int db, CommandFlags flags, RedisCommand command,
}
}
internal
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key0
,
RedisValue
[]
values
,
RedisKey
key1
)
internal
static
Message
Create
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key0
,
RedisValue
[]
values
,
in
RedisKey
key1
)
{
if
(
values
==
null
)
throw
new
ArgumentNullException
(
nameof
(
values
));
return
new
CommandKeyValuesKeyMessage
(
db
,
flags
,
command
,
key0
,
values
,
key1
);
...
...
@@ -583,7 +583,7 @@ internal static CommandFlags SetMasterSlaveFlags(CommandFlags everything, Comman
internal
void
Cancel
()
=>
resultBox
?.
Cancel
();
// true if ready to be completed (i.e. false if re-issued to another server)
internal
bool
ComputeResult
(
PhysicalConnection
connection
,
RawResult
result
)
internal
bool
ComputeResult
(
PhysicalConnection
connection
,
in
RawResult
result
)
{
var
box
=
resultBox
;
try
...
...
@@ -746,7 +746,7 @@ internal abstract class CommandChannelBase : Message
{
protected
readonly
RedisChannel
Channel
;
protected
CommandChannelBase
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisChannel
channel
)
:
base
(
db
,
flags
,
command
)
protected
CommandChannelBase
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisChannel
channel
)
:
base
(
db
,
flags
,
command
)
{
channel
.
AssertNotNull
();
Channel
=
channel
;
...
...
@@ -759,7 +759,7 @@ internal abstract class CommandKeyBase : Message
{
protected
readonly
RedisKey
Key
;
protected
CommandKeyBase
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
)
:
base
(
db
,
flags
,
command
)
protected
CommandKeyBase
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
)
:
base
(
db
,
flags
,
command
)
{
key
.
AssertNotNull
();
Key
=
key
;
...
...
@@ -775,7 +775,7 @@ public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
private
sealed
class
CommandChannelMessage
:
CommandChannelBase
{
public
CommandChannelMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisChannel
channel
)
:
base
(
db
,
flags
,
command
,
channel
)
public
CommandChannelMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisChannel
channel
)
:
base
(
db
,
flags
,
command
,
channel
)
{
}
protected
override
void
WriteImpl
(
PhysicalConnection
physical
)
{
...
...
@@ -788,7 +788,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandChannelValueMessage
:
CommandChannelBase
{
private
readonly
RedisValue
value
;
public
CommandChannelValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisChannel
channel
,
RedisValue
value
)
:
base
(
db
,
flags
,
command
,
channel
)
public
CommandChannelValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisChannel
channel
,
in
RedisValue
value
)
:
base
(
db
,
flags
,
command
,
channel
)
{
value
.
AssertNotNull
();
this
.
value
=
value
;
...
...
@@ -806,7 +806,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandKeyKeyKeyMessage
:
CommandKeyBase
{
private
readonly
RedisKey
key1
,
key2
;
public
CommandKeyKeyKeyMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key0
,
RedisKey
key1
,
RedisKey
key2
)
:
base
(
db
,
flags
,
command
,
key0
)
public
CommandKeyKeyKeyMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key0
,
in
RedisKey
key1
,
in
RedisKey
key2
)
:
base
(
db
,
flags
,
command
,
key0
)
{
key1
.
AssertNotNull
();
key2
.
AssertNotNull
();
...
...
@@ -834,7 +834,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
class
CommandKeyKeyMessage
:
CommandKeyBase
{
protected
readonly
RedisKey
key1
;
public
CommandKeyKeyMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key0
,
RedisKey
key1
)
:
base
(
db
,
flags
,
command
,
key0
)
public
CommandKeyKeyMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key0
,
in
RedisKey
key1
)
:
base
(
db
,
flags
,
command
,
key0
)
{
key1
.
AssertNotNull
();
this
.
key1
=
key1
;
...
...
@@ -858,7 +858,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandKeyKeysMessage
:
CommandKeyBase
{
private
readonly
RedisKey
[]
keys
;
public
CommandKeyKeysMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisKey
[]
keys
)
:
base
(
db
,
flags
,
command
,
key
)
public
CommandKeyKeysMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
RedisKey
[]
keys
)
:
base
(
db
,
flags
,
command
,
key
)
{
for
(
int
i
=
0
;
i
<
keys
.
Length
;
i
++)
{
...
...
@@ -892,7 +892,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandKeyKeyValueMessage
:
CommandKeyKeyMessage
{
private
readonly
RedisValue
value
;
public
CommandKeyKeyValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key0
,
RedisKey
key1
,
RedisValue
value
)
:
base
(
db
,
flags
,
command
,
key0
,
key1
)
public
CommandKeyKeyValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key0
,
in
RedisKey
key1
,
in
RedisValue
value
)
:
base
(
db
,
flags
,
command
,
key0
,
key1
)
{
value
.
AssertNotNull
();
this
.
value
=
value
;
...
...
@@ -911,7 +911,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandKeyMessage
:
CommandKeyBase
{
public
CommandKeyMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
)
:
base
(
db
,
flags
,
command
,
key
)
public
CommandKeyMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
)
:
base
(
db
,
flags
,
command
,
key
)
{
}
protected
override
void
WriteImpl
(
PhysicalConnection
physical
)
{
...
...
@@ -980,7 +980,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandKeyValueMessage
:
CommandKeyBase
{
private
readonly
RedisValue
value
;
public
CommandKeyValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisValue
value
)
:
base
(
db
,
flags
,
command
,
key
)
public
CommandKeyValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
in
RedisValue
value
)
:
base
(
db
,
flags
,
command
,
key
)
{
value
.
AssertNotNull
();
this
.
value
=
value
;
...
...
@@ -999,7 +999,7 @@ private sealed class CommandKeyValuesKeyMessage : CommandKeyBase
{
private
readonly
RedisKey
key1
;
private
readonly
RedisValue
[]
values
;
public
CommandKeyValuesKeyMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key0
,
RedisValue
[]
values
,
RedisKey
key1
)
:
base
(
db
,
flags
,
command
,
key0
)
public
CommandKeyValuesKeyMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key0
,
RedisValue
[]
values
,
in
RedisKey
key1
)
:
base
(
db
,
flags
,
command
,
key0
)
{
for
(
int
i
=
0
;
i
<
values
.
Length
;
i
++)
{
...
...
@@ -1029,7 +1029,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandKeyValuesMessage
:
CommandKeyBase
{
private
readonly
RedisValue
[]
values
;
public
CommandKeyValuesMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisValue
[]
values
)
:
base
(
db
,
flags
,
command
,
key
)
public
CommandKeyValuesMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
RedisValue
[]
values
)
:
base
(
db
,
flags
,
command
,
key
)
{
for
(
int
i
=
0
;
i
<
values
.
Length
;
i
++)
{
...
...
@@ -1050,7 +1050,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandKeyValueValueMessage
:
CommandKeyBase
{
private
readonly
RedisValue
value0
,
value1
;
public
CommandKeyValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisValue
value0
,
RedisValue
value1
)
:
base
(
db
,
flags
,
command
,
key
)
public
CommandKeyValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
in
RedisValue
value0
,
in
RedisValue
value1
)
:
base
(
db
,
flags
,
command
,
key
)
{
value0
.
AssertNotNull
();
value1
.
AssertNotNull
();
...
...
@@ -1071,7 +1071,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandKeyValueValueValueMessage
:
CommandKeyBase
{
private
readonly
RedisValue
value0
,
value1
,
value2
;
public
CommandKeyValueValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisValue
value0
,
RedisValue
value1
,
RedisValue
value2
)
:
base
(
db
,
flags
,
command
,
key
)
public
CommandKeyValueValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
in
RedisValue
value0
,
in
RedisValue
value1
,
in
RedisValue
value2
)
:
base
(
db
,
flags
,
command
,
key
)
{
value0
.
AssertNotNull
();
value1
.
AssertNotNull
();
...
...
@@ -1095,7 +1095,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandKeyValueValueValueValueMessage
:
CommandKeyBase
{
private
readonly
RedisValue
value0
,
value1
,
value2
,
value3
;
public
CommandKeyValueValueValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
key
,
RedisValue
value0
,
RedisValue
value1
,
RedisValue
value2
,
RedisValue
value3
)
:
base
(
db
,
flags
,
command
,
key
)
public
CommandKeyValueValueValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisKey
key
,
in
RedisValue
value0
,
in
RedisValue
value1
,
in
RedisValue
value2
,
in
RedisValue
value3
)
:
base
(
db
,
flags
,
command
,
key
)
{
value0
.
AssertNotNull
();
value1
.
AssertNotNull
();
...
...
@@ -1164,7 +1164,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandValueChannelMessage
:
CommandChannelBase
{
private
readonly
RedisValue
value
;
public
CommandValueChannelMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value
,
RedisChannel
channel
)
:
base
(
db
,
flags
,
command
,
channel
)
public
CommandValueChannelMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value
,
in
RedisChannel
channel
)
:
base
(
db
,
flags
,
command
,
channel
)
{
value
.
AssertNotNull
();
this
.
value
=
value
;
...
...
@@ -1183,7 +1183,7 @@ private sealed class CommandValueKeyMessage : CommandKeyBase
{
private
readonly
RedisValue
value
;
public
CommandValueKeyMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value
,
RedisKey
key
)
:
base
(
db
,
flags
,
command
,
key
)
public
CommandValueKeyMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value
,
in
RedisKey
key
)
:
base
(
db
,
flags
,
command
,
key
)
{
value
.
AssertNotNull
();
this
.
value
=
value
;
...
...
@@ -1207,7 +1207,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandValueMessage
:
Message
{
private
readonly
RedisValue
value
;
public
CommandValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value
)
:
base
(
db
,
flags
,
command
)
public
CommandValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value
)
:
base
(
db
,
flags
,
command
)
{
value
.
AssertNotNull
();
this
.
value
=
value
;
...
...
@@ -1224,7 +1224,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandValueValueMessage
:
Message
{
private
readonly
RedisValue
value0
,
value1
;
public
CommandValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value0
,
RedisValue
value1
)
:
base
(
db
,
flags
,
command
)
public
CommandValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value0
,
in
RedisValue
value1
)
:
base
(
db
,
flags
,
command
)
{
value0
.
AssertNotNull
();
value1
.
AssertNotNull
();
...
...
@@ -1244,7 +1244,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandValueValueValueMessage
:
Message
{
private
readonly
RedisValue
value0
,
value1
,
value2
;
public
CommandValueValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value0
,
RedisValue
value1
,
RedisValue
value2
)
:
base
(
db
,
flags
,
command
)
public
CommandValueValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value0
,
in
RedisValue
value1
,
in
RedisValue
value2
)
:
base
(
db
,
flags
,
command
)
{
value0
.
AssertNotNull
();
value1
.
AssertNotNull
();
...
...
@@ -1267,7 +1267,7 @@ protected override void WriteImpl(PhysicalConnection physical)
private
sealed
class
CommandValueValueValueValueValueMessage
:
Message
{
private
readonly
RedisValue
value0
,
value1
,
value2
,
value3
,
value4
;
public
CommandValueValueValueValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisValue
value0
,
RedisValue
value1
,
RedisValue
value2
,
RedisValue
value3
,
RedisValue
value4
)
:
base
(
db
,
flags
,
command
)
public
CommandValueValueValueValueValueMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
in
RedisValue
value0
,
in
RedisValue
value1
,
in
RedisValue
value2
,
in
RedisValue
value3
,
in
RedisValue
value4
)
:
base
(
db
,
flags
,
command
)
{
value0
.
AssertNotNull
();
value1
.
AssertNotNull
();
...
...
src/StackExchange.Redis/PhysicalConnection.cs
View file @
743d3ca8
...
...
@@ -631,7 +631,7 @@ internal void SetUnknownDatabase()
currentDatabase
=
-
1
;
}
internal
void
Write
(
RedisKey
key
)
internal
void
Write
(
in
RedisKey
key
)
{
var
val
=
key
.
KeyValue
;
if
(
val
is
string
s
)
...
...
@@ -644,13 +644,13 @@ internal void Write(RedisKey key)
}
}
internal
void
Write
(
RedisChannel
channel
)
internal
void
Write
(
in
RedisChannel
channel
)
=>
WriteUnifiedPrefixedBlob
(
_ioPipe
.
Output
,
ChannelPrefix
,
channel
.
Value
);
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
internal
void
WriteBulkString
(
RedisValue
value
)
internal
void
WriteBulkString
(
in
RedisValue
value
)
=>
WriteBulkString
(
value
,
_ioPipe
.
Output
);
internal
static
void
WriteBulkString
(
RedisValue
value
,
PipeWriter
output
)
internal
static
void
WriteBulkString
(
in
RedisValue
value
,
PipeWriter
output
)
{
switch
(
value
.
Type
)
{
...
...
@@ -889,7 +889,7 @@ private static void WriteUnifiedSpan(PipeWriter writer, ReadOnlySpan<byte> value
{
var
span
=
writer
.
GetSpan
(
5
+
MaxInt32TextLen
+
value
.
Length
);
span
[
0
]
=
(
byte
)
'$'
;
int
bytes
=
AppendToSpan
Span
(
span
,
value
,
1
);
int
bytes
=
AppendToSpan
(
span
,
value
,
1
);
writer
.
Advance
(
bytes
);
}
else
...
...
@@ -906,7 +906,7 @@ private static void WriteUnifiedSpan(PipeWriter writer, ReadOnlySpan<byte> value
}
}
private
static
int
AppendToSpanCommand
(
Span
<
byte
>
span
,
CommandBytes
value
,
int
offset
=
0
)
private
static
int
AppendToSpanCommand
(
Span
<
byte
>
span
,
in
CommandBytes
value
,
int
offset
=
0
)
{
span
[
offset
++]
=
(
byte
)
'$'
;
int
len
=
value
.
Length
;
...
...
@@ -916,7 +916,9 @@ private static int AppendToSpanCommand(Span<byte> span, CommandBytes value, int
return
WriteCrlf
(
span
,
offset
);
}
private
static
int
AppendToSpanSpan
(
Span
<
byte
>
span
,
ReadOnlySpan
<
byte
>
value
,
int
offset
=
0
)
#pragma warning disable RCS1231 // Make parameter ref read-only. - spans are tiny
private
static
int
AppendToSpan
(
Span
<
byte
>
span
,
ReadOnlySpan
<
byte
>
value
,
int
offset
=
0
)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{
offset
=
WriteRaw
(
span
,
value
.
Length
,
offset
:
offset
);
value
.
CopyTo
(
span
.
Slice
(
offset
,
value
.
Length
));
...
...
@@ -1230,7 +1232,7 @@ internal async ValueTask<bool> ConnectedAsync(Socket socket, TextWriter log, Soc
}
}
private
void
MatchResult
(
RawResult
result
)
private
void
MatchResult
(
in
RawResult
result
)
{
// check to see if it could be an out-of-band pubsub message
if
(
connectionType
==
ConnectionType
.
Subscription
&&
result
.
Type
==
ResultType
.
MultiBulk
)
...
...
src/StackExchange.Redis/RawResult.cs
View file @
743d3ca8
...
...
@@ -27,7 +27,7 @@ namespace StackExchange.Redis
private
const
ResultType
NonNullFlag
=
(
ResultType
)
128
;
public
RawResult
(
ResultType
resultType
,
ReadOnlySequence
<
byte
>
payload
,
bool
isNull
)
public
RawResult
(
ResultType
resultType
,
in
ReadOnlySequence
<
byte
>
payload
,
bool
isNull
)
{
switch
(
resultType
)
{
...
...
@@ -91,7 +91,7 @@ public override string ToString()
public
Tokenizer
GetEnumerator
()
=>
this
;
private
BufferReader
_value
;
public
Tokenizer
(
ReadOnlySequence
<
byte
>
value
)
public
Tokenizer
(
in
ReadOnlySequence
<
byte
>
value
)
{
_value
=
new
BufferReader
(
value
);
Current
=
default
;
...
...
@@ -209,7 +209,7 @@ internal void Recycle(int limit = -1)
}
}
internal
bool
IsEqual
(
CommandBytes
expected
)
internal
bool
IsEqual
(
in
CommandBytes
expected
)
{
if
(
expected
.
Length
!=
Payload
.
Length
)
return
false
;
return
new
CommandBytes
(
Payload
).
Equals
(
expected
);
...
...
@@ -236,7 +236,7 @@ internal unsafe bool IsEqual(byte[] expected)
return
true
;
}
internal
bool
StartsWith
(
CommandBytes
expected
)
internal
bool
StartsWith
(
in
CommandBytes
expected
)
{
var
len
=
expected
.
Length
;
if
(
len
>
Payload
.
Length
)
return
false
;
...
...
src/StackExchange.Redis/RedisChannel.cs
View file @
743d3ca8
...
...
@@ -56,73 +56,93 @@ private static bool DeterminePatternBased(byte[] value, PatternMode mode)
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
!=(
RedisChannel
x
,
RedisChannel
y
)
=>
!(
x
==
y
);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Indicate whether two channel names are not equal
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
!=(
string
x
,
RedisChannel
y
)
=>
!(
x
==
y
);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Indicate whether two channel names are not equal
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
!=(
byte
[]
x
,
RedisChannel
y
)
=>
!(
x
==
y
);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Indicate whether two channel names are not equal
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
!=(
RedisChannel
x
,
string
y
)
=>
!(
x
==
y
);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Indicate whether two channel names are not equal
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
!=(
RedisChannel
x
,
byte
[]
y
)
=>
!(
x
==
y
);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Indicate whether two channel names are equal
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
==(
RedisChannel
x
,
RedisChannel
y
)
=>
x
.
IsPatternBased
==
y
.
IsPatternBased
&&
RedisValue
.
Equals
(
x
.
Value
,
y
.
Value
);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Indicate whether two channel names are equal
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
==(
string
x
,
RedisChannel
y
)
=>
RedisValue
.
Equals
(
x
==
null
?
null
:
Encoding
.
UTF8
.
GetBytes
(
x
),
y
.
Value
);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Indicate whether two channel names are equal
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
==(
byte
[]
x
,
RedisChannel
y
)
=>
RedisValue
.
Equals
(
x
,
y
.
Value
);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Indicate whether two channel names are equal
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
==(
RedisChannel
x
,
string
y
)
=>
RedisValue
.
Equals
(
x
.
Value
,
y
==
null
?
null
:
Encoding
.
UTF8
.
GetBytes
(
y
));
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Indicate whether two channel names are equal
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
bool
operator
==(
RedisChannel
x
,
byte
[]
y
)
=>
RedisValue
.
Equals
(
x
.
Value
,
y
);
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// See Object.Equals
...
...
@@ -223,13 +243,17 @@ public enum PatternMode
/// Obtain the channel name as a <see cref="T:byte[]"/>.
/// </summary>
/// <param name="key">The channel to get a byte[] from.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
implicit
operator
byte
[]
(
RedisChannel
key
)
=>
key
.
Value
;
#pragma warning restore RCS1231 // Make parameter ref read-only.
/// <summary>
/// Obtain the channel name as a <see cref="string"/>.
/// </summary>
/// <param name="key">The channel to get a string from.</param>
#pragma warning disable RCS1231 // Make parameter ref read-only. - public API
public
static
implicit
operator
string
(
RedisChannel
key
)
#pragma warning restore RCS1231 // Make parameter ref read-only.
{
var
arr
=
key
.
Value
;
if
(
arr
==
null
)
return
null
;
...
...
src/StackExchange.Redis/RedisDatabase.cs
View file @
743d3ca8
...
...
@@ -176,7 +176,7 @@ private static readonly RedisValue
COUNT
=
Encoding
.
ASCII
.
GetBytes
(
"COUNT"
),
ASC
=
Encoding
.
ASCII
.
GetBytes
(
"ASC"
),
DESC
=
Encoding
.
ASCII
.
GetBytes
(
"DESC"
);
private
Message
GetGeoRadiusMessage
(
RedisKey
key
,
RedisValue
?
member
,
double
longitude
,
double
latitude
,
double
radius
,
GeoUnit
unit
,
int
count
,
Order
?
order
,
GeoRadiusOptions
options
,
CommandFlags
flags
)
private
Message
GetGeoRadiusMessage
(
in
RedisKey
key
,
RedisValue
?
member
,
double
longitude
,
double
latitude
,
double
radius
,
GeoUnit
unit
,
int
count
,
Order
?
order
,
GeoRadiusOptions
options
,
CommandFlags
flags
)
{
var
redisValues
=
new
List
<
RedisValue
>();
RedisCommand
command
;
...
...
@@ -2419,7 +2419,7 @@ public Task<RedisValue> StringSetRangeAsync(RedisKey key, long offset, RedisValu
return
ExecuteAsync
(
msg
,
ResultProcessor
.
RedisValue
);
}
private
Message
GetExpiryMessage
(
RedisKey
key
,
CommandFlags
flags
,
TimeSpan
?
expiry
,
out
ServerEndPoint
server
)
private
Message
GetExpiryMessage
(
in
RedisKey
key
,
CommandFlags
flags
,
TimeSpan
?
expiry
,
out
ServerEndPoint
server
)
{
TimeSpan
duration
;
if
(
expiry
==
null
||
(
duration
=
expiry
.
Value
)
==
TimeSpan
.
MaxValue
)
...
...
@@ -2441,7 +2441,7 @@ private Message GetExpiryMessage(RedisKey key, CommandFlags flags, TimeSpan? exp
return
Message
.
Create
(
Database
,
flags
,
RedisCommand
.
EXPIRE
,
key
,
seconds
);
}
private
Message
GetExpiryMessage
(
RedisKey
key
,
CommandFlags
flags
,
DateTime
?
expiry
,
out
ServerEndPoint
server
)
private
Message
GetExpiryMessage
(
in
RedisKey
key
,
CommandFlags
flags
,
DateTime
?
expiry
,
out
ServerEndPoint
server
)
{
DateTime
when
;
if
(
expiry
==
null
||
(
when
=
expiry
.
Value
)
==
DateTime
.
MaxValue
)
...
...
@@ -3686,7 +3686,7 @@ private class StringGetWithExpiryMessage : Message.CommandKeyBase, IMultiMessage
private
readonly
RedisCommand
ttlCommand
;
private
ResultBox
<
TimeSpan
?>
box
;
public
StringGetWithExpiryMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
ttlCommand
,
RedisKey
key
)
public
StringGetWithExpiryMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
ttlCommand
,
in
RedisKey
key
)
:
base
(
db
,
flags
,
RedisCommand
.
GET
,
key
)
{
this
.
ttlCommand
=
ttlCommand
;
...
...
src/StackExchange.Redis/RedisSubscriber.cs
View file @
743d3ca8
...
...
@@ -29,7 +29,7 @@ public partial class ConnectionMultiplexer
return
false
;
}
internal
Task
AddSubscription
(
RedisChannel
channel
,
Action
<
RedisChannel
,
RedisValue
>
handler
,
CommandFlags
flags
,
object
asyncState
)
internal
Task
AddSubscription
(
in
RedisChannel
channel
,
Action
<
RedisChannel
,
RedisValue
>
handler
,
CommandFlags
flags
,
object
asyncState
)
{
if
(
handler
!=
null
)
{
...
...
@@ -52,7 +52,7 @@ internal Task AddSubscription(RedisChannel channel, Action<RedisChannel, RedisVa
return
CompletedTask
<
bool
>.
Default
(
asyncState
);
}
internal
ServerEndPoint
GetSubscribedServer
(
RedisChannel
channel
)
internal
ServerEndPoint
GetSubscribedServer
(
in
RedisChannel
channel
)
{
if
(!
channel
.
IsNullOrEmpty
)
{
...
...
@@ -67,7 +67,7 @@ internal ServerEndPoint GetSubscribedServer(RedisChannel channel)
return
null
;
}
internal
void
OnMessage
(
RedisChannel
subscription
,
RedisChannel
channel
,
RedisValue
payload
)
internal
void
OnMessage
(
in
RedisChannel
subscription
,
in
RedisChannel
channel
,
in
RedisValue
payload
)
{
ICompletable
completable
=
null
;
lock
(
subscriptions
)
...
...
@@ -100,7 +100,7 @@ internal Task RemoveAllSubscriptions(CommandFlags flags, object asyncState)
return
last
;
}
internal
Task
RemoveSubscription
(
RedisChannel
channel
,
Action
<
RedisChannel
,
RedisValue
>
handler
,
CommandFlags
flags
,
object
asyncState
)
internal
Task
RemoveSubscription
(
in
RedisChannel
channel
,
Action
<
RedisChannel
,
RedisValue
>
handler
,
CommandFlags
flags
,
object
asyncState
)
{
lock
(
subscriptions
)
{
...
...
@@ -171,7 +171,7 @@ public ICompletable ForSyncShutdown()
var
syncHandler
=
_syncHandler
;
return
syncHandler
==
null
?
null
:
new
MessageCompletable
(
default
,
default
,
syncHandler
,
null
);
}
public
ICompletable
ForInvoke
(
RedisChannel
channel
,
RedisValue
message
)
public
ICompletable
ForInvoke
(
in
RedisChannel
channel
,
in
RedisValue
message
)
{
var
syncHandler
=
_syncHandler
;
var
asyncHandler
=
_asyncHandler
;
...
...
@@ -193,7 +193,7 @@ public bool Remove(bool asAsync, Action<RedisChannel, RedisValue> value)
return
_syncHandler
==
null
&&
_asyncHandler
==
null
;
}
public
Task
SubscribeToServer
(
ConnectionMultiplexer
multiplexer
,
RedisChannel
channel
,
CommandFlags
flags
,
object
asyncState
,
bool
internalCall
)
public
Task
SubscribeToServer
(
ConnectionMultiplexer
multiplexer
,
in
RedisChannel
channel
,
CommandFlags
flags
,
object
asyncState
,
bool
internalCall
)
{
var
cmd
=
channel
.
IsPatternBased
?
RedisCommand
.
PSUBSCRIBE
:
RedisCommand
.
SUBSCRIBE
;
var
selected
=
multiplexer
.
SelectServer
(
cmd
,
flags
,
default
(
RedisKey
));
...
...
@@ -205,7 +205,7 @@ public Task SubscribeToServer(ConnectionMultiplexer multiplexer, RedisChannel ch
return
selected
.
WriteDirectAsync
(
msg
,
ResultProcessor
.
TrackSubscriptions
,
asyncState
);
}
public
Task
UnsubscribeFromServer
(
RedisChannel
channel
,
CommandFlags
flags
,
object
asyncState
,
bool
internalCall
)
public
Task
UnsubscribeFromServer
(
in
RedisChannel
channel
,
CommandFlags
flags
,
object
asyncState
,
bool
internalCall
)
{
var
oldOwner
=
Interlocked
.
Exchange
(
ref
owner
,
null
);
if
(
oldOwner
==
null
)
return
null
;
...
...
@@ -218,7 +218,7 @@ public Task UnsubscribeFromServer(RedisChannel channel, CommandFlags flags, obje
internal
ServerEndPoint
GetOwner
()
=>
Volatile
.
Read
(
ref
owner
);
internal
void
Resubscribe
(
RedisChannel
channel
,
ServerEndPoint
server
)
internal
void
Resubscribe
(
in
RedisChannel
channel
,
ServerEndPoint
server
)
{
if
(
server
!=
null
&&
Interlocked
.
CompareExchange
(
ref
owner
,
server
,
server
)
==
server
)
{
...
...
@@ -229,7 +229,7 @@ internal void Resubscribe(RedisChannel channel, ServerEndPoint server)
}
}
internal
bool
Validate
(
ConnectionMultiplexer
multiplexer
,
RedisChannel
channel
)
internal
bool
Validate
(
ConnectionMultiplexer
multiplexer
,
in
RedisChannel
channel
)
{
bool
changed
=
false
;
var
oldOwner
=
Volatile
.
Read
(
ref
owner
);
...
...
toys/StackExchange.Redis.Server/RespServer.cs
View file @
743d3ca8
...
...
@@ -122,7 +122,7 @@ public RespCommand(RedisCommandAttribute attrib, MethodInfo method, RespServer s
public
bool
HasSubCommands
=>
_subcommands
!=
null
;
internal
RespCommand
WithSubCommands
(
RespCommand
[]
subs
)
=>
new
RespCommand
(
this
,
subs
);
private
RespCommand
(
RespCommand
parent
,
RespCommand
[]
subs
)
private
RespCommand
(
in
RespCommand
parent
,
RespCommand
[]
subs
)
{
if
(
parent
.
IsSubCommand
)
throw
new
InvalidOperationException
(
"Cannot have nested sub-commands"
);
if
(
parent
.
HasSubCommands
)
throw
new
InvalidOperationException
(
"Already has sub-commands"
);
...
...
@@ -155,7 +155,7 @@ public RespCommand Resolve(in RedisRequest request)
}
return
this
;
}
public
TypedRedisValue
Execute
(
RedisClient
client
,
RedisRequest
request
)
public
TypedRedisValue
Execute
(
RedisClient
client
,
in
RedisRequest
request
)
{
var
args
=
request
.
Count
;
if
(!
CheckArity
(
request
.
Count
))
...
...
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