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
d5ca30fa
Commit
d5ca30fa
authored
Mar 26, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The .Assert() names were amibguous (unclear of intent), and I didn't like the stack-copy semantic
parent
e7a3485e
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
93 additions
and
65 deletions
+93
-65
Message.cs
StackExchange.Redis/StackExchange/Redis/Message.cs
+67
-36
PhysicalConnection.cs
...kExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
+4
-4
RawResult.cs
StackExchange.Redis/StackExchange/Redis/RawResult.cs
+1
-1
RedisChannel.cs
StackExchange.Redis/StackExchange/Redis/RedisChannel.cs
+1
-2
RedisDatabase.cs
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
+4
-4
RedisKey.cs
StackExchange.Redis/StackExchange/Redis/RedisKey.cs
+1
-2
RedisTransaction.cs
StackExchange.Redis/StackExchange/Redis/RedisTransaction.cs
+2
-2
RedisValue.cs
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
+1
-2
ResultProcessor.cs
StackExchange.Redis/StackExchange/Redis/ResultProcessor.cs
+12
-12
No files found.
StackExchange.Redis/StackExchange/Redis/Message.cs
View file @
d5ca30fa
This diff is collapsed.
Click to expand it.
StackExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
View file @
d5ca30fa
...
@@ -588,16 +588,16 @@ void MatchResult(RawResult result)
...
@@ -588,16 +588,16 @@ void MatchResult(RawResult result)
if
(
connectionType
==
ConnectionType
.
Subscription
&&
result
.
Type
==
ResultType
.
MultiBulk
)
if
(
connectionType
==
ConnectionType
.
Subscription
&&
result
.
Type
==
ResultType
.
MultiBulk
)
{
// out of band message does not match to a queued message
{
// out of band message does not match to a queued message
var
items
=
result
.
GetItems
();
var
items
=
result
.
GetItems
();
if
(
items
.
Length
>=
3
&&
items
[
0
].
Assert
(
message
))
if
(
items
.
Length
>=
3
&&
items
[
0
].
IsEqual
(
message
))
{
{
// special-case the configuration change broadcasts (we don't keep that in the usual pub/sub registry)
// special-case the configuration change broadcasts (we don't keep that in the usual pub/sub registry)
var
configChanged
=
multiplexer
.
ConfigurationChangedChannel
;
var
configChanged
=
multiplexer
.
ConfigurationChangedChannel
;
if
(
configChanged
!=
null
&&
items
[
1
].
Assert
(
configChanged
))
if
(
configChanged
!=
null
&&
items
[
1
].
IsEqual
(
configChanged
))
{
{
EndPoint
blame
=
null
;
EndPoint
blame
=
null
;
try
try
{
{
if
(!
items
[
2
].
Assert
(
RedisLiterals
.
ByteWildcard
))
if
(!
items
[
2
].
IsEqual
(
RedisLiterals
.
ByteWildcard
))
{
{
blame
=
Format
.
TryParseEndPoint
(
items
[
2
].
GetString
());
blame
=
Format
.
TryParseEndPoint
(
items
[
2
].
GetString
());
}
}
...
@@ -616,7 +616,7 @@ void MatchResult(RawResult result)
...
@@ -616,7 +616,7 @@ void MatchResult(RawResult result)
}
}
return
;
// AND STOP PROCESSING!
return
;
// AND STOP PROCESSING!
}
}
else
if
(
items
.
Length
>=
4
&&
items
[
0
].
Assert
(
pmessage
))
else
if
(
items
.
Length
>=
4
&&
items
[
0
].
IsEqual
(
pmessage
))
{
{
var
channel
=
items
[
2
].
AsRedisChannel
(
ChannelPrefix
);
var
channel
=
items
[
2
].
AsRedisChannel
(
ChannelPrefix
);
multiplexer
.
Trace
(
"PMESSAGE: "
+
channel
,
physicalName
);
multiplexer
.
Trace
(
"PMESSAGE: "
+
channel
,
physicalName
);
...
...
StackExchange.Redis/StackExchange/Redis/RawResult.cs
View file @
d5ca30fa
...
@@ -117,7 +117,7 @@ internal RedisValue AsRedisValue()
...
@@ -117,7 +117,7 @@ internal RedisValue AsRedisValue()
throw
new
InvalidCastException
(
"Cannot convert to RedisValue: "
+
resultType
);
throw
new
InvalidCastException
(
"Cannot convert to RedisValue: "
+
resultType
);
}
}
internal
unsafe
bool
Assert
(
byte
[]
expected
)
internal
unsafe
bool
IsEqual
(
byte
[]
expected
)
{
{
if
(
expected
==
null
)
throw
new
ArgumentNullException
(
"expected"
);
if
(
expected
==
null
)
throw
new
ArgumentNullException
(
"expected"
);
if
(
expected
.
Length
!=
count
)
return
false
;
if
(
expected
.
Length
!=
count
)
return
false
;
...
...
StackExchange.Redis/StackExchange/Redis/RedisChannel.cs
View file @
d5ca30fa
...
@@ -169,10 +169,9 @@ internal static bool AssertStarts(byte[] value, byte[] expected)
...
@@ -169,10 +169,9 @@ internal static bool AssertStarts(byte[] value, byte[] expected)
return
true
;
return
true
;
}
}
internal
RedisChannel
Assert
()
internal
void
AssertNotNull
()
{
{
if
(
IsNull
)
throw
new
ArgumentException
(
"A null key is not valid in this context"
);
if
(
IsNull
)
throw
new
ArgumentException
(
"A null key is not valid in this context"
);
return
this
;
}
}
internal
RedisChannel
Clone
()
internal
RedisChannel
Clone
()
...
...
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
View file @
d5ca30fa
...
@@ -1958,10 +1958,10 @@ public ScriptEvalMessage(int db, CommandFlags flags, RedisCommand command, strin
...
@@ -1958,10 +1958,10 @@ public ScriptEvalMessage(int db, CommandFlags flags, RedisCommand command, strin
if
(
script
==
null
)
throw
new
ArgumentNullException
(
"script"
);
if
(
script
==
null
)
throw
new
ArgumentNullException
(
"script"
);
this
.
script
=
script
;
this
.
script
=
script
;
for
(
int
i
=
0
;
i
<
keys
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
keys
.
Length
;
i
++)
keys
[
i
].
Assert
();
keys
[
i
].
Assert
NotNull
();
this
.
keys
=
keys
;
this
.
keys
=
keys
;
for
(
int
i
=
0
;
i
<
values
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
values
.
Length
;
i
++)
values
[
i
].
Assert
();
values
[
i
].
Assert
NotNull
();
this
.
values
=
values
;
this
.
values
=
values
;
}
}
public
override
int
GetHashSlot
(
ServerSelectionStrategy
serverSelectionStrategy
)
public
override
int
GetHashSlot
(
ServerSelectionStrategy
serverSelectionStrategy
)
...
@@ -2021,10 +2021,10 @@ sealed class SortedSetCombineAndStoreCommandMessage : Message.CommandKeyBase //
...
@@ -2021,10 +2021,10 @@ sealed class SortedSetCombineAndStoreCommandMessage : Message.CommandKeyBase //
public
SortedSetCombineAndStoreCommandMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
destination
,
RedisKey
[]
keys
,
RedisValue
[]
values
)
:
base
(
db
,
flags
,
command
,
destination
)
public
SortedSetCombineAndStoreCommandMessage
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
,
RedisKey
destination
,
RedisKey
[]
keys
,
RedisValue
[]
values
)
:
base
(
db
,
flags
,
command
,
destination
)
{
{
for
(
int
i
=
0
;
i
<
keys
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
keys
.
Length
;
i
++)
keys
[
i
].
Assert
();
keys
[
i
].
Assert
NotNull
();
this
.
keys
=
keys
;
this
.
keys
=
keys
;
for
(
int
i
=
0
;
i
<
values
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
values
.
Length
;
i
++)
values
[
i
].
Assert
();
values
[
i
].
Assert
NotNull
();
this
.
values
=
values
;
this
.
values
=
values
;
}
}
public
override
int
GetHashSlot
(
ServerSelectionStrategy
serverSelectionStrategy
)
public
override
int
GetHashSlot
(
ServerSelectionStrategy
serverSelectionStrategy
)
...
...
StackExchange.Redis/StackExchange/Redis/RedisKey.cs
View file @
d5ca30fa
...
@@ -151,10 +151,9 @@ internal RedisValue AsRedisValue()
...
@@ -151,10 +151,9 @@ internal RedisValue AsRedisValue()
return
value
;
return
value
;
}
}
internal
RedisKey
Assert
()
internal
void
AssertNotNull
()
{
{
if
(
IsNull
)
throw
new
ArgumentException
(
"A null key is not valid in this context"
);
if
(
IsNull
)
throw
new
ArgumentException
(
"A null key is not valid in this context"
);
return
this
;
}
}
/// <summary>
/// <summary>
...
...
StackExchange.Redis/StackExchange/Redis/RedisTransaction.cs
View file @
d5ca30fa
...
@@ -143,7 +143,7 @@ class QueuedProcessor : ResultProcessor<bool>
...
@@ -143,7 +143,7 @@ class QueuedProcessor : ResultProcessor<bool>
static
readonly
byte
[]
QUEUED
=
Encoding
.
UTF8
.
GetBytes
(
"QUEUED"
);
static
readonly
byte
[]
QUEUED
=
Encoding
.
UTF8
.
GetBytes
(
"QUEUED"
);
protected
override
bool
SetResultCore
(
PhysicalConnection
connection
,
Message
message
,
RawResult
result
)
protected
override
bool
SetResultCore
(
PhysicalConnection
connection
,
Message
message
,
RawResult
result
)
{
{
if
(
result
.
Type
==
ResultType
.
SimpleString
&&
result
.
Assert
(
QUEUED
))
if
(
result
.
Type
==
ResultType
.
SimpleString
&&
result
.
IsEqual
(
QUEUED
))
{
{
var
q
=
message
as
QueuedMessage
;
var
q
=
message
as
QueuedMessage
;
if
(
q
!=
null
)
q
.
WasQueued
=
true
;
if
(
q
!=
null
)
q
.
WasQueued
=
true
;
...
@@ -394,7 +394,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
...
@@ -394,7 +394,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
switch
(
result
.
Type
)
switch
(
result
.
Type
)
{
{
case
ResultType
.
SimpleString
:
case
ResultType
.
SimpleString
:
if
(
tran
.
IsAborted
&&
result
.
Assert
(
RedisLiterals
.
BytesOK
))
if
(
tran
.
IsAborted
&&
result
.
IsEqual
(
RedisLiterals
.
BytesOK
))
{
{
connection
.
Multiplexer
.
Trace
(
"Acknowledging UNWATCH (aborted electively)"
);
connection
.
Multiplexer
.
Trace
(
"Acknowledging UNWATCH (aborted electively)"
);
SetResult
(
message
,
false
);
SetResult
(
message
,
false
);
...
...
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
View file @
d5ca30fa
...
@@ -221,10 +221,9 @@ internal static bool TryParseInt64(byte[] value, int offset, int count, out long
...
@@ -221,10 +221,9 @@ internal static bool TryParseInt64(byte[] value, int offset, int count, out long
}
}
}
}
internal
RedisValue
Assert
()
internal
void
AssertNotNull
()
{
{
if
(
IsNull
)
throw
new
ArgumentException
(
"A null value is not valid in this context"
);
if
(
IsNull
)
throw
new
ArgumentException
(
"A null value is not valid in this context"
);
return
this
;
}
}
/// <summary>
/// <summary>
/// Creates a new RedisValue from an Int32
/// Creates a new RedisValue from an Int32
...
...
StackExchange.Redis/StackExchange/Redis/ResultProcessor.cs
View file @
d5ca30fa
...
@@ -301,8 +301,8 @@ public static bool TryGet(RawResult result, out bool value)
...
@@ -301,8 +301,8 @@ public static bool TryGet(RawResult result, out bool value)
case
ResultType
.
Integer
:
case
ResultType
.
Integer
:
case
ResultType
.
SimpleString
:
case
ResultType
.
SimpleString
:
case
ResultType
.
BulkString
:
case
ResultType
.
BulkString
:
if
(
result
.
Assert
(
one
))
{
value
=
true
;
return
true
;
}
if
(
result
.
IsEqual
(
one
))
{
value
=
true
;
return
true
;
}
else
if
(
result
.
Assert
(
zero
))
{
value
=
false
;
return
true
;
}
else
if
(
result
.
IsEqual
(
zero
))
{
value
=
false
;
return
true
;
}
break
;
break
;
}
}
value
=
false
;
value
=
false
;
...
@@ -507,7 +507,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
...
@@ -507,7 +507,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
for
(
int
i
=
0
;
i
<
count
;
i
++)
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
{
var
key
=
arr
[
i
*
2
];
var
key
=
arr
[
i
*
2
];
if
(
key
.
Assert
(
timeout
)
&&
arr
[(
i
*
2
)
+
1
].
TryGetInt64
(
out
i64
))
if
(
key
.
IsEqual
(
timeout
)
&&
arr
[(
i
*
2
)
+
1
].
TryGetInt64
(
out
i64
))
{
{
// note the configuration is in seconds
// note the configuration is in seconds
int
timeoutSeconds
=
checked
((
int
)
i64
),
targetSeconds
;
int
timeoutSeconds
=
checked
((
int
)
i64
),
targetSeconds
;
...
@@ -525,21 +525,21 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
...
@@ -525,21 +525,21 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
server
.
WriteEverySeconds
=
targetSeconds
;
server
.
WriteEverySeconds
=
targetSeconds
;
}
}
}
}
else
if
(
key
.
Assert
(
databases
)
&&
arr
[(
i
*
2
)
+
1
].
TryGetInt64
(
out
i64
))
else
if
(
key
.
IsEqual
(
databases
)
&&
arr
[(
i
*
2
)
+
1
].
TryGetInt64
(
out
i64
))
{
{
int
dbCount
=
checked
((
int
)
i64
);
int
dbCount
=
checked
((
int
)
i64
);
server
.
Multiplexer
.
Trace
(
"Auto-configured databases: "
+
dbCount
);
server
.
Multiplexer
.
Trace
(
"Auto-configured databases: "
+
dbCount
);
server
.
Databases
=
dbCount
;
server
.
Databases
=
dbCount
;
}
}
else
if
(
key
.
Assert
(
slave_read_only
))
else
if
(
key
.
IsEqual
(
slave_read_only
))
{
{
var
val
=
arr
[(
i
*
2
)
+
1
];
var
val
=
arr
[(
i
*
2
)
+
1
];
if
(
val
.
Assert
(
yes
))
if
(
val
.
IsEqual
(
yes
))
{
{
server
.
SlaveReadOnly
=
true
;
server
.
SlaveReadOnly
=
true
;
server
.
Multiplexer
.
Trace
(
"Auto-configured slave-read-only: true"
);
server
.
Multiplexer
.
Trace
(
"Auto-configured slave-read-only: true"
);
}
}
else
if
(
val
.
Assert
(
no
))
else
if
(
val
.
IsEqual
(
no
))
{
{
server
.
SlaveReadOnly
=
false
;
server
.
SlaveReadOnly
=
false
;
server
.
Multiplexer
.
Trace
(
"Auto-configured slave-read-only: false"
);
server
.
Multiplexer
.
Trace
(
"Auto-configured slave-read-only: false"
);
...
@@ -572,7 +572,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
...
@@ -572,7 +572,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
switch
(
result
.
Type
)
switch
(
result
.
Type
)
{
{
case
ResultType
.
SimpleString
:
case
ResultType
.
SimpleString
:
if
(
result
.
Assert
(
RedisLiterals
.
BytesOK
))
if
(
result
.
IsEqual
(
RedisLiterals
.
BytesOK
))
{
{
SetResult
(
message
,
true
);
SetResult
(
message
,
true
);
}
}
...
@@ -749,7 +749,7 @@ public ExpectBasicStringProcessor(byte[] value)
...
@@ -749,7 +749,7 @@ public ExpectBasicStringProcessor(byte[] value)
}
}
protected
override
bool
SetResultCore
(
PhysicalConnection
connection
,
Message
message
,
RawResult
result
)
protected
override
bool
SetResultCore
(
PhysicalConnection
connection
,
Message
message
,
RawResult
result
)
{
{
if
(
result
.
Assert
(
expected
))
if
(
result
.
IsEqual
(
expected
))
{
{
SetResult
(
message
,
true
);
SetResult
(
message
,
true
);
return
true
;
return
true
;
...
@@ -1042,7 +1042,7 @@ public override bool SetResult(PhysicalConnection connection, Message message, R
...
@@ -1042,7 +1042,7 @@ public override bool SetResult(PhysicalConnection connection, Message message, R
var
final
=
base
.
SetResult
(
connection
,
message
,
result
);
var
final
=
base
.
SetResult
(
connection
,
message
,
result
);
if
(
result
.
IsError
)
if
(
result
.
IsError
)
{
{
if
(
result
.
Assert
(
authFail
))
if
(
result
.
IsEqual
(
authFail
))
{
{
connection
.
RecordConnectionFailed
(
ConnectionFailureType
.
AuthenticationFailure
);
connection
.
RecordConnectionFailed
(
ConnectionFailureType
.
AuthenticationFailure
);
}
}
...
@@ -1064,10 +1064,10 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
...
@@ -1064,10 +1064,10 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
switch
(
message
.
Command
)
switch
(
message
.
Command
)
{
{
case
RedisCommand
.
ECHO
:
case
RedisCommand
.
ECHO
:
happy
=
result
.
Type
==
ResultType
.
BulkString
&&
(!
establishConnection
||
result
.
Assert
(
connection
.
Multiplexer
.
UniqueId
));
happy
=
result
.
Type
==
ResultType
.
BulkString
&&
(!
establishConnection
||
result
.
IsEqual
(
connection
.
Multiplexer
.
UniqueId
));
break
;
break
;
case
RedisCommand
.
PING
:
case
RedisCommand
.
PING
:
happy
=
result
.
Type
==
ResultType
.
SimpleString
&&
result
.
Assert
(
RedisLiterals
.
BytesPONG
);
happy
=
result
.
Type
==
ResultType
.
SimpleString
&&
result
.
IsEqual
(
RedisLiterals
.
BytesPONG
);
break
;
break
;
case
RedisCommand
.
TIME
:
case
RedisCommand
.
TIME
:
happy
=
result
.
Type
==
ResultType
.
MultiBulk
&&
result
.
GetItems
().
Length
==
2
;
happy
=
result
.
Type
==
ResultType
.
MultiBulk
&&
result
.
GetItems
().
Length
==
2
;
...
...
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