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
36f5a354
Commit
36f5a354
authored
Aug 01, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Property cleanup
parent
e3493310
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
81 deletions
+76
-81
RedisRequest.cs
StackExchange.Redis.Server/RedisRequest.cs
+1
-1
RawResult.cs
StackExchange.Redis/StackExchange/Redis/RawResult.cs
+35
-37
RedisDatabase.cs
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
+5
-6
RedisKey.cs
StackExchange.Redis/StackExchange/Redis/RedisKey.cs
+32
-34
RedisResult.cs
StackExchange.Redis/StackExchange/Redis/RedisResult.cs
+3
-3
No files found.
StackExchange.Redis.Server/RedisRequest.cs
View file @
36f5a354
...
...
@@ -51,7 +51,7 @@ public RedisChannel GetChannel(int index, RedisChannel.PatternMode mode)
internal
bool
TryGetCommandBytes
(
int
i
,
out
CommandBytes
command
)
{
var
payload
=
_inner
[
i
].
Direcy
Payload
;
var
payload
=
_inner
[
i
].
Payload
;
if
(
payload
.
Length
>
CommandBytes
.
MaxLength
)
{
command
=
default
;
...
...
StackExchange.Redis/StackExchange/Redis/RawResult.cs
View file @
36f5a354
...
...
@@ -11,20 +11,18 @@ namespace StackExchange.Redis
{
get
{
if
(
index
>=
_i
temsCount
)
throw
new
IndexOutOfRangeException
();
if
(
index
>=
I
temsCount
)
throw
new
IndexOutOfRangeException
();
return
_itemsOversized
[
index
];
}
}
internal
int
ItemsCount
=>
_itemsCount
;
internal
int
ItemsCount
{
get
;
}
internal
ReadOnlySequence
<
byte
>
Payload
{
get
;
}
internal
static
readonly
RawResult
NullMultiBulk
=
new
RawResult
(
null
,
0
);
internal
static
readonly
RawResult
EmptyMultiBulk
=
new
RawResult
(
Array
.
Empty
<
RawResult
>(),
0
);
internal
static
readonly
RawResult
Nil
=
default
;
private
readonly
ReadOnlySequence
<
byte
>
_payload
;
internal
ReadOnlySequence
<
byte
>
DirecyPayload
=>
_payload
;
// note: can't use Memory<RawResult> here - struct recursion breaks runtimr
private
readonly
RawResult
[]
_itemsOversized
;
private
readonly
int
_itemsCount
;
private
readonly
ResultType
_type
;
private
const
ResultType
NonNullFlag
=
(
ResultType
)
128
;
...
...
@@ -43,18 +41,18 @@ public RawResult(ResultType resultType, ReadOnlySequence<byte> payload, bool isN
}
if
(!
isNull
)
resultType
|=
NonNullFlag
;
_type
=
resultType
;
_p
ayload
=
payload
;
P
ayload
=
payload
;
_itemsOversized
=
default
;
_i
temsCount
=
default
;
I
temsCount
=
default
;
}
public
RawResult
(
RawResult
[]
itemsOversized
,
int
itemCount
)
{
_type
=
ResultType
.
MultiBulk
;
if
(
itemsOversized
!=
null
)
_type
|=
NonNullFlag
;
_p
ayload
=
default
;
P
ayload
=
default
;
_itemsOversized
=
itemsOversized
;
_i
temsCount
=
itemCount
;
I
temsCount
=
itemCount
;
}
public
bool
IsError
=>
Type
==
ResultType
.
Error
;
...
...
@@ -74,15 +72,15 @@ public override string ToString()
case
ResultType
.
Error
:
return
$"
{
Type
}
:
{
GetString
()}
"
;
case
ResultType
.
BulkString
:
return
$"
{
Type
}
:
{
_p
ayload
.
Length
}
bytes"
;
return
$"
{
Type
}
:
{
P
ayload
.
Length
}
bytes"
;
case
ResultType
.
MultiBulk
:
return
$"
{
Type
}
:
{
_i
temsCount
}
items"
;
return
$"
{
Type
}
:
{
I
temsCount
}
items"
;
default
:
return
$"(unknown:
{
Type
}
)"
;
}
}
public
Tokenizer
GetInlineTokenizer
()
=>
new
Tokenizer
(
_p
ayload
);
public
Tokenizer
GetInlineTokenizer
()
=>
new
Tokenizer
(
P
ayload
);
internal
ref
struct
Tokenizer
{
...
...
@@ -144,7 +142,7 @@ internal RedisChannel AsRedisChannel(byte[] channelPrefix, RedisChannel.PatternM
}
if
(
StartsWith
(
channelPrefix
))
{
byte
[]
copy
=
_p
ayload
.
Slice
(
channelPrefix
.
Length
).
ToArray
();
byte
[]
copy
=
P
ayload
.
Slice
(
channelPrefix
.
Length
).
ToArray
();
return
new
RedisChannel
(
copy
,
mode
);
}
return
default
(
RedisChannel
);
...
...
@@ -186,7 +184,7 @@ internal void Recycle(int limit = -1)
var
arr
=
_itemsOversized
;
if
(
arr
!=
null
)
{
if
(
limit
<
0
)
limit
=
_i
temsCount
;
if
(
limit
<
0
)
limit
=
I
temsCount
;
for
(
int
i
=
0
;
i
<
limit
;
i
++)
{
arr
[
i
].
Recycle
();
...
...
@@ -197,15 +195,15 @@ internal void Recycle(int limit = -1)
internal
bool
IsEqual
(
CommandBytes
expected
)
{
if
(
expected
.
Length
!=
_p
ayload
.
Length
)
return
false
;
return
new
CommandBytes
(
_p
ayload
).
Equals
(
expected
);
if
(
expected
.
Length
!=
P
ayload
.
Length
)
return
false
;
return
new
CommandBytes
(
P
ayload
).
Equals
(
expected
);
}
internal
unsafe
bool
IsEqual
(
byte
[]
expected
)
{
if
(
expected
==
null
)
throw
new
ArgumentNullException
(
nameof
(
expected
));
var
rangeToCheck
=
_p
ayload
;
var
rangeToCheck
=
P
ayload
;
if
(
expected
.
Length
!=
rangeToCheck
.
Length
)
return
false
;
if
(
rangeToCheck
.
IsSingleSegment
)
return
rangeToCheck
.
First
.
Span
.
SequenceEqual
(
expected
);
...
...
@@ -225,17 +223,17 @@ internal unsafe bool IsEqual(byte[] expected)
internal
bool
StartsWith
(
CommandBytes
expected
)
{
var
len
=
expected
.
Length
;
if
(
len
>
_p
ayload
.
Length
)
return
false
;
if
(
len
>
P
ayload
.
Length
)
return
false
;
var
rangeToCheck
=
_p
ayload
.
Slice
(
0
,
len
);
var
rangeToCheck
=
P
ayload
.
Slice
(
0
,
len
);
return
new
CommandBytes
(
rangeToCheck
).
Equals
(
expected
);
}
internal
bool
StartsWith
(
byte
[]
expected
)
{
if
(
expected
==
null
)
throw
new
ArgumentNullException
(
nameof
(
expected
));
if
(
expected
.
Length
>
_p
ayload
.
Length
)
return
false
;
if
(
expected
.
Length
>
P
ayload
.
Length
)
return
false
;
var
rangeToCheck
=
_p
ayload
.
Slice
(
0
,
expected
.
Length
);
var
rangeToCheck
=
P
ayload
.
Slice
(
0
,
expected
.
Length
);
if
(
rangeToCheck
.
IsSingleSegment
)
return
rangeToCheck
.
First
.
Span
.
SequenceEqual
(
expected
);
int
offset
=
0
;
...
...
@@ -254,15 +252,15 @@ internal byte[] GetBlob()
{
if
(
IsNull
)
return
null
;
if
(
_p
ayload
.
IsEmpty
)
return
Array
.
Empty
<
byte
>();
if
(
P
ayload
.
IsEmpty
)
return
Array
.
Empty
<
byte
>();
return
_p
ayload
.
ToArray
();
return
P
ayload
.
ToArray
();
}
internal
bool
GetBoolean
()
{
if
(
_p
ayload
.
Length
!=
1
)
throw
new
InvalidCastException
();
switch
(
_p
ayload
.
First
.
Span
[
0
])
if
(
P
ayload
.
Length
!=
1
)
throw
new
InvalidCastException
();
switch
(
P
ayload
.
First
.
Span
[
0
])
{
case
(
byte
)
'1'
:
return
true
;
case
(
byte
)
'0'
:
return
false
;
...
...
@@ -273,13 +271,13 @@ internal bool GetBoolean()
internal
ReadOnlySpan
<
RawResult
>
GetItems
()
{
if
(
Type
==
ResultType
.
MultiBulk
)
return
new
ReadOnlySpan
<
RawResult
>(
_itemsOversized
,
0
,
_i
temsCount
);
return
new
ReadOnlySpan
<
RawResult
>(
_itemsOversized
,
0
,
I
temsCount
);
throw
new
InvalidOperationException
();
}
internal
ReadOnlyMemory
<
RawResult
>
GetItemsMemory
()
{
if
(
Type
==
ResultType
.
MultiBulk
)
return
new
ReadOnlyMemory
<
RawResult
>(
_itemsOversized
,
0
,
_i
temsCount
);
return
new
ReadOnlyMemory
<
RawResult
>(
_itemsOversized
,
0
,
I
temsCount
);
throw
new
InvalidOperationException
();
}
...
...
@@ -396,11 +394,11 @@ internal string[] GetItemsAsStrings()
internal
unsafe
string
GetString
()
{
if
(
IsNull
)
return
null
;
if
(
_p
ayload
.
IsEmpty
)
return
""
;
if
(
P
ayload
.
IsEmpty
)
return
""
;
if
(
_p
ayload
.
IsSingleSegment
)
if
(
P
ayload
.
IsSingleSegment
)
{
var
span
=
_p
ayload
.
First
.
Span
;
var
span
=
P
ayload
.
First
.
Span
;
fixed
(
byte
*
ptr
=
&
MemoryMarshal
.
GetReference
(
span
))
{
return
Encoding
.
UTF8
.
GetString
(
ptr
,
span
.
Length
);
...
...
@@ -408,7 +406,7 @@ internal unsafe string GetString()
}
var
decoder
=
Encoding
.
UTF8
.
GetDecoder
();
int
charCount
=
0
;
foreach
(
var
segment
in
_p
ayload
)
foreach
(
var
segment
in
P
ayload
)
{
var
span
=
segment
.
Span
;
if
(
span
.
IsEmpty
)
continue
;
...
...
@@ -425,7 +423,7 @@ internal unsafe string GetString()
fixed
(
char
*
sPtr
=
s
)
{
char
*
cPtr
=
sPtr
;
foreach
(
var
segment
in
_p
ayload
)
foreach
(
var
segment
in
P
ayload
)
{
var
span
=
segment
.
Span
;
if
(
span
.
IsEmpty
)
continue
;
...
...
@@ -458,16 +456,16 @@ internal bool TryGetDouble(out double val)
internal
bool
TryGetInt64
(
out
long
value
)
{
if
(
IsNull
||
_payload
.
IsEmpty
||
_p
ayload
.
Length
>
PhysicalConnection
.
MaxInt64TextLen
)
if
(
IsNull
||
Payload
.
IsEmpty
||
P
ayload
.
Length
>
PhysicalConnection
.
MaxInt64TextLen
)
{
value
=
0
;
return
false
;
}
if
(
_payload
.
IsSingleSegment
)
return
RedisValue
.
TryParseInt64
(
_p
ayload
.
First
.
Span
,
out
value
);
if
(
Payload
.
IsSingleSegment
)
return
RedisValue
.
TryParseInt64
(
P
ayload
.
First
.
Span
,
out
value
);
Span
<
byte
>
span
=
stackalloc
byte
[(
int
)
_p
ayload
.
Length
];
// we already checked the length was <= MaxInt64TextLen
_p
ayload
.
CopyTo
(
span
);
Span
<
byte
>
span
=
stackalloc
byte
[(
int
)
P
ayload
.
Length
];
// we already checked the length was <= MaxInt64TextLen
P
ayload
.
CopyTo
(
span
);
return
RedisValue
.
TryParseInt64
(
span
,
out
value
);
}
}
...
...
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
View file @
36f5a354
...
...
@@ -3231,24 +3231,23 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
internal
sealed
class
ExecuteMessage
:
Message
{
private
readonly
CommandBytes
_command
;
private
readonly
ICollection
<
object
>
_args
;
public
new
CommandBytes
Command
{
get
;
}
public
new
CommandBytes
Command
=>
_command
;
public
ExecuteMessage
(
CommandMap
map
,
int
db
,
CommandFlags
flags
,
string
command
,
ICollection
<
object
>
args
)
:
base
(
db
,
flags
,
RedisCommand
.
UNKNOWN
)
{
if
(
args
!=
null
&&
args
.
Count
>=
PhysicalConnection
.
REDIS_MAX_ARGS
)
// using >= here because we will be adding 1 for the command itself (which is an arg for the purposes of the multi-bulk protocol)
{
throw
ExceptionFactory
.
TooManyArgs
(
command
,
args
.
Count
);
}
_c
ommand
=
map
?.
GetBytes
(
command
)
??
default
;
if
(
_c
ommand
.
IsEmpty
)
throw
ExceptionFactory
.
CommandDisabled
(
command
);
C
ommand
=
map
?.
GetBytes
(
command
)
??
default
;
if
(
C
ommand
.
IsEmpty
)
throw
ExceptionFactory
.
CommandDisabled
(
command
);
_args
=
args
??
Array
.
Empty
<
object
>();
}
protected
override
void
WriteImpl
(
PhysicalConnection
physical
)
{
physical
.
WriteHeader
(
RedisCommand
.
UNKNOWN
,
_args
.
Count
,
_c
ommand
);
physical
.
WriteHeader
(
RedisCommand
.
UNKNOWN
,
_args
.
Count
,
C
ommand
);
foreach
(
object
arg
in
_args
)
{
if
(
arg
is
RedisKey
key
)
...
...
@@ -3268,7 +3267,7 @@ protected override void WriteImpl(PhysicalConnection physical)
}
}
public
override
string
CommandAndKey
=>
_c
ommand
.
ToString
();
public
override
string
CommandAndKey
=>
C
ommand
.
ToString
();
public
override
int
GetHashSlot
(
ServerSelectionStrategy
serverSelectionStrategy
)
{
...
...
StackExchange.Redis/StackExchange/Redis/RedisKey.cs
View file @
36f5a354
...
...
@@ -8,31 +8,29 @@ namespace StackExchange.Redis
/// </summary>
public
readonly
struct
RedisKey
:
IEquatable
<
RedisKey
>
{
private
readonly
byte
[]
keyPrefix
;
private
readonly
object
keyValue
;
// always either a string or a byte[]
internal
RedisKey
(
byte
[]
keyPrefix
,
object
keyValue
)
{
this
.
k
eyPrefix
=
keyPrefix
?.
Length
==
0
?
null
:
keyPrefix
;
this
.
k
eyValue
=
keyValue
;
K
eyPrefix
=
keyPrefix
?.
Length
==
0
?
null
:
keyPrefix
;
K
eyValue
=
keyValue
;
}
internal
RedisKey
AsPrefix
()
=>
new
RedisKey
((
byte
[])
this
,
null
);
internal
bool
IsNull
=>
keyPrefix
==
null
&&
k
eyValue
==
null
;
internal
bool
IsNull
=>
KeyPrefix
==
null
&&
K
eyValue
==
null
;
internal
bool
IsEmpty
{
get
{
if
(
k
eyPrefix
!=
null
)
return
false
;
if
(
k
eyValue
==
null
)
return
true
;
if
(
keyValue
is
string
)
return
((
string
)
keyValue
)
.
Length
==
0
;
return
((
byte
[])
k
eyValue
).
Length
==
0
;
if
(
K
eyPrefix
!=
null
)
return
false
;
if
(
K
eyValue
==
null
)
return
true
;
if
(
KeyValue
is
string
s
)
return
s
.
Length
==
0
;
return
((
byte
[])
K
eyValue
).
Length
==
0
;
}
}
internal
byte
[]
KeyPrefix
=>
keyPrefix
;
internal
object
KeyValue
=>
keyValue
;
internal
byte
[]
KeyPrefix
{
get
;
}
internal
object
KeyValue
{
get
;
}
/// <summary>
/// Indicate whether two keys are not equal
...
...
@@ -74,35 +72,35 @@ internal bool IsEmpty
/// </summary>
/// <param name="x">The first <see cref="RedisChannel"/> to compare.</param>
/// <param name="y">The second <see cref="RedisChannel"/> to compare.</param>
public
static
bool
operator
==(
RedisKey
x
,
RedisKey
y
)
=>
CompositeEquals
(
x
.
keyPrefix
,
x
.
keyValue
,
y
.
keyPrefix
,
y
.
k
eyValue
);
public
static
bool
operator
==(
RedisKey
x
,
RedisKey
y
)
=>
CompositeEquals
(
x
.
KeyPrefix
,
x
.
KeyValue
,
y
.
KeyPrefix
,
y
.
K
eyValue
);
/// <summary>
/// Indicate whether two keys 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>
public
static
bool
operator
==(
string
x
,
RedisKey
y
)
=>
CompositeEquals
(
null
,
x
,
y
.
keyPrefix
,
y
.
k
eyValue
);
public
static
bool
operator
==(
string
x
,
RedisKey
y
)
=>
CompositeEquals
(
null
,
x
,
y
.
KeyPrefix
,
y
.
K
eyValue
);
/// <summary>
/// Indicate whether two keys 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>
public
static
bool
operator
==(
byte
[]
x
,
RedisKey
y
)
=>
CompositeEquals
(
null
,
x
,
y
.
keyPrefix
,
y
.
k
eyValue
);
public
static
bool
operator
==(
byte
[]
x
,
RedisKey
y
)
=>
CompositeEquals
(
null
,
x
,
y
.
KeyPrefix
,
y
.
K
eyValue
);
/// <summary>
/// Indicate whether two keys 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>
public
static
bool
operator
==(
RedisKey
x
,
string
y
)
=>
CompositeEquals
(
x
.
keyPrefix
,
x
.
k
eyValue
,
null
,
y
);
public
static
bool
operator
==(
RedisKey
x
,
string
y
)
=>
CompositeEquals
(
x
.
KeyPrefix
,
x
.
K
eyValue
,
null
,
y
);
/// <summary>
/// Indicate whether two keys 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>
public
static
bool
operator
==(
RedisKey
x
,
byte
[]
y
)
=>
CompositeEquals
(
x
.
keyPrefix
,
x
.
k
eyValue
,
null
,
y
);
public
static
bool
operator
==(
RedisKey
x
,
byte
[]
y
)
=>
CompositeEquals
(
x
.
KeyPrefix
,
x
.
K
eyValue
,
null
,
y
);
/// <summary>
/// See Object.Equals
...
...
@@ -112,11 +110,11 @@ public override bool Equals(object obj)
{
if
(
obj
is
RedisKey
other
)
{
return
CompositeEquals
(
keyPrefix
,
keyValue
,
other
.
keyPrefix
,
other
.
k
eyValue
);
return
CompositeEquals
(
KeyPrefix
,
KeyValue
,
other
.
KeyPrefix
,
other
.
K
eyValue
);
}
if
(
obj
is
string
||
obj
is
byte
[])
{
return
CompositeEquals
(
keyPrefix
,
k
eyValue
,
null
,
obj
);
return
CompositeEquals
(
KeyPrefix
,
K
eyValue
,
null
,
obj
);
}
return
false
;
}
...
...
@@ -125,7 +123,7 @@ public override bool Equals(object obj)
/// Indicate whether two keys are equal
/// </summary>
/// <param name="other">The <see cref="RedisKey"/> to compare to.</param>
public
bool
Equals
(
RedisKey
other
)
=>
CompositeEquals
(
keyPrefix
,
keyValue
,
other
.
keyPrefix
,
other
.
k
eyValue
);
public
bool
Equals
(
RedisKey
other
)
=>
CompositeEquals
(
KeyPrefix
,
KeyValue
,
other
.
KeyPrefix
,
other
.
K
eyValue
);
private
static
bool
CompositeEquals
(
byte
[]
keyPrefix0
,
object
keyValue0
,
byte
[]
keyPrefix1
,
object
keyValue1
)
{
...
...
@@ -146,8 +144,8 @@ private static bool CompositeEquals(byte[] keyPrefix0, object keyValue0, byte[]
/// </summary>
public
override
int
GetHashCode
()
{
int
chk0
=
keyPrefix
==
null
?
0
:
RedisValue
.
GetHashCode
(
k
eyPrefix
),
chk1
=
keyValue
is
string
?
keyValue
.
GetHashCode
()
:
RedisValue
.
GetHashCode
((
byte
[])
k
eyValue
);
int
chk0
=
KeyPrefix
==
null
?
0
:
RedisValue
.
GetHashCode
(
K
eyPrefix
),
chk1
=
KeyValue
is
string
?
KeyValue
.
GetHashCode
()
:
RedisValue
.
GetHashCode
((
byte
[])
K
eyValue
);
return
unchecked
((
17
*
chk0
)
+
chk1
);
}
...
...
@@ -159,7 +157,7 @@ public override int GetHashCode()
internal
RedisValue
AsRedisValue
()
{
if
(
keyPrefix
==
null
&&
keyValue
is
string
)
return
(
string
)
k
eyValue
;
if
(
KeyPrefix
==
null
&&
KeyValue
is
string
)
return
(
string
)
K
eyValue
;
return
(
byte
[])
this
;
}
...
...
@@ -191,7 +189,7 @@ internal void AssertNotNull()
/// Obtain the <see cref="RedisKey"/> as a <see cref="T:byte[]"/>.
/// </summary>
/// <param name="key">The key to get a byte array for.</param>
public
static
implicit
operator
byte
[]
(
RedisKey
key
)
=>
ConcatenateBytes
(
key
.
keyPrefix
,
key
.
k
eyValue
,
null
);
public
static
implicit
operator
byte
[]
(
RedisKey
key
)
=>
ConcatenateBytes
(
key
.
KeyPrefix
,
key
.
K
eyValue
,
null
);
/// <summary>
/// Obtain the key as a <see cref="string"/>.
...
...
@@ -200,13 +198,13 @@ internal void AssertNotNull()
public
static
implicit
operator
string
(
RedisKey
key
)
{
byte
[]
arr
;
if
(
key
.
k
eyPrefix
==
null
)
if
(
key
.
K
eyPrefix
==
null
)
{
if
(
key
.
k
eyValue
==
null
)
return
null
;
if
(
key
.
K
eyValue
==
null
)
return
null
;
if
(
key
.
keyValue
is
string
)
return
(
string
)
key
.
k
eyValue
;
if
(
key
.
KeyValue
is
string
)
return
(
string
)
key
.
K
eyValue
;
arr
=
(
byte
[])
key
.
k
eyValue
;
arr
=
(
byte
[])
key
.
K
eyValue
;
}
else
{
...
...
@@ -231,20 +229,20 @@ internal void AssertNotNull()
[
Obsolete
]
public
static
RedisKey
operator
+(
RedisKey
x
,
RedisKey
y
)
{
return
new
RedisKey
(
ConcatenateBytes
(
x
.
keyPrefix
,
x
.
keyValue
,
y
.
keyPrefix
),
y
.
k
eyValue
);
return
new
RedisKey
(
ConcatenateBytes
(
x
.
KeyPrefix
,
x
.
KeyValue
,
y
.
KeyPrefix
),
y
.
K
eyValue
);
}
internal
static
RedisKey
WithPrefix
(
byte
[]
prefix
,
RedisKey
value
)
{
if
(
prefix
==
null
||
prefix
.
Length
==
0
)
return
value
;
if
(
value
.
keyPrefix
==
null
)
return
new
RedisKey
(
prefix
,
value
.
k
eyValue
);
if
(
value
.
keyValue
==
null
)
return
new
RedisKey
(
prefix
,
value
.
k
eyPrefix
);
if
(
value
.
KeyPrefix
==
null
)
return
new
RedisKey
(
prefix
,
value
.
K
eyValue
);
if
(
value
.
KeyValue
==
null
)
return
new
RedisKey
(
prefix
,
value
.
K
eyPrefix
);
// two prefixes; darn
byte
[]
copy
=
new
byte
[
prefix
.
Length
+
value
.
k
eyPrefix
.
Length
];
byte
[]
copy
=
new
byte
[
prefix
.
Length
+
value
.
K
eyPrefix
.
Length
];
Buffer
.
BlockCopy
(
prefix
,
0
,
copy
,
0
,
prefix
.
Length
);
Buffer
.
BlockCopy
(
value
.
keyPrefix
,
0
,
copy
,
prefix
.
Length
,
value
.
k
eyPrefix
.
Length
);
return
new
RedisKey
(
copy
,
value
.
k
eyValue
);
Buffer
.
BlockCopy
(
value
.
KeyPrefix
,
0
,
copy
,
prefix
.
Length
,
value
.
K
eyPrefix
.
Length
);
return
new
RedisKey
(
copy
,
value
.
K
eyValue
);
}
internal
static
byte
[]
ConcatenateBytes
(
byte
[]
a
,
object
b
,
byte
[]
c
)
...
...
@@ -252,7 +250,7 @@ internal static byte[] ConcatenateBytes(byte[] a, object b, byte[] c)
if
((
a
==
null
||
a
.
Length
==
0
)
&&
(
c
==
null
||
c
.
Length
==
0
))
{
if
(
b
==
null
)
return
null
;
if
(
b
is
string
)
return
Encoding
.
UTF8
.
GetBytes
((
string
)
b
);
if
(
b
is
string
s
)
return
Encoding
.
UTF8
.
GetBytes
(
s
);
return
(
byte
[])
b
;
}
...
...
StackExchange.Redis/StackExchange/Redis/RedisResult.cs
View file @
36f5a354
...
...
@@ -394,12 +394,12 @@ public ErrorRedisResult(string value)
private
sealed
class
SingleRedisResult
:
RedisResult
{
private
readonly
RedisValue
_value
;
p
rivate
readonly
ResultType
_resultType
;
public
override
ResultType
Type
=>
_resultType
;
p
ublic
override
ResultType
Type
{
get
;
}
public
SingleRedisResult
(
RedisValue
value
,
ResultType
?
resultType
)
{
_value
=
value
;
_result
Type
=
resultType
??
(
value
.
IsInteger
?
ResultType
.
Integer
:
ResultType
.
BulkString
);
Type
=
resultType
??
(
value
.
IsInteger
?
ResultType
.
Integer
:
ResultType
.
BulkString
);
}
public
override
bool
IsNull
=>
_value
.
IsNull
;
...
...
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