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
18d14db3
Commit
18d14db3
authored
Jul 09, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #859 - add RedisValue.StartsWith
parent
bea5dbfe
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
4 deletions
+67
-4
RedisValueEquivalency.cs
StackExchange.Redis.Tests/RedisValueEquivalency.cs
+35
-0
RedisResult.cs
StackExchange.Redis/StackExchange/Redis/RedisResult.cs
+4
-4
RedisValue.cs
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
+28
-0
No files found.
StackExchange.Redis.Tests/RedisValueEquivalency.cs
View file @
18d14db3
...
@@ -150,5 +150,40 @@ private static void CheckString(RedisValue value, string expected)
...
@@ -150,5 +150,40 @@ private static void CheckString(RedisValue value, string expected)
}
}
private
static
byte
[]
Bytes
(
string
s
)
=>
s
==
null
?
null
:
Encoding
.
UTF8
.
GetBytes
(
s
);
private
static
byte
[]
Bytes
(
string
s
)
=>
s
==
null
?
null
:
Encoding
.
UTF8
.
GetBytes
(
s
);
[
Fact
]
public
void
RedisValueStartsWith
()
{
// test strings
RedisValue
x
=
"abc"
;
Assert
.
True
(
x
.
StartsWith
(
"a"
));
Assert
.
True
(
x
.
StartsWith
(
"ab"
));
Assert
.
True
(
x
.
StartsWith
(
"abc"
));
Assert
.
False
(
x
.
StartsWith
(
"abd"
));
Assert
.
False
(
x
.
StartsWith
(
"abcd"
));
Assert
.
False
(
x
.
StartsWith
(
123
));
Assert
.
False
(
x
.
StartsWith
(
false
));
// test binary
x
=
Encoding
.
ASCII
.
GetBytes
(
"abc"
);
Assert
.
True
(
x
.
StartsWith
(
"a"
));
Assert
.
True
(
x
.
StartsWith
(
"ab"
));
Assert
.
True
(
x
.
StartsWith
(
"abc"
));
Assert
.
False
(
x
.
StartsWith
(
"abd"
));
Assert
.
False
(
x
.
StartsWith
(
"abcd"
));
Assert
.
False
(
x
.
StartsWith
(
123
));
Assert
.
False
(
x
.
StartsWith
(
false
));
Assert
.
True
(
x
.
StartsWith
(
Encoding
.
ASCII
.
GetBytes
(
"a"
)));
Assert
.
True
(
x
.
StartsWith
(
Encoding
.
ASCII
.
GetBytes
(
"ab"
)));
Assert
.
True
(
x
.
StartsWith
(
Encoding
.
ASCII
.
GetBytes
(
"abc"
)));
Assert
.
False
(
x
.
StartsWith
(
Encoding
.
ASCII
.
GetBytes
(
"abd"
)));
Assert
.
False
(
x
.
StartsWith
(
Encoding
.
ASCII
.
GetBytes
(
"abcd"
)));
x
=
10
;
// integers are effectively strings in this context
Assert
.
True
(
x
.
StartsWith
(
1
));
Assert
.
True
(
x
.
StartsWith
(
10
));
Assert
.
False
(
x
.
StartsWith
(
100
));
}
}
}
}
}
StackExchange.Redis/StackExchange/Redis/RedisResult.cs
View file @
18d14db3
...
@@ -60,7 +60,7 @@ internal static RedisResult TryCreate(PhysicalConnection connection, RawResult r
...
@@ -60,7 +60,7 @@ internal static RedisResult TryCreate(PhysicalConnection connection, RawResult r
/// <summary>
/// <summary>
/// Indicate the type of result that was received from redis
/// Indicate the type of result that was received from redis
/// </summary>
/// </summary>
public
abstract
ResultType
Result
Type
{
get
;
}
public
abstract
ResultType
Type
{
get
;
}
/// <summary>
/// <summary>
/// Indicates whether this result was a null result
/// Indicates whether this result was a null result
...
@@ -199,7 +199,7 @@ private sealed class ArrayRedisResult : RedisResult
...
@@ -199,7 +199,7 @@ private sealed class ArrayRedisResult : RedisResult
public
override
bool
IsNull
=>
value
==
null
;
public
override
bool
IsNull
=>
value
==
null
;
private
readonly
RedisResult
[]
value
;
private
readonly
RedisResult
[]
value
;
public
override
ResultType
Result
Type
=>
ResultType
.
MultiBulk
;
public
override
ResultType
Type
=>
ResultType
.
MultiBulk
;
public
ArrayRedisResult
(
RedisResult
[]
value
)
public
ArrayRedisResult
(
RedisResult
[]
value
)
{
{
this
.
value
=
value
??
throw
new
ArgumentNullException
(
nameof
(
value
));
this
.
value
=
value
??
throw
new
ArgumentNullException
(
nameof
(
value
));
...
@@ -302,7 +302,7 @@ private sealed class ErrorRedisResult : RedisResult
...
@@ -302,7 +302,7 @@ private sealed class ErrorRedisResult : RedisResult
{
{
private
readonly
string
value
;
private
readonly
string
value
;
public
override
ResultType
Result
Type
=>
ResultType
.
Error
;
public
override
ResultType
Type
=>
ResultType
.
Error
;
public
ErrorRedisResult
(
string
value
)
public
ErrorRedisResult
(
string
value
)
{
{
this
.
value
=
value
??
throw
new
ArgumentNullException
(
nameof
(
value
));
this
.
value
=
value
??
throw
new
ArgumentNullException
(
nameof
(
value
));
...
@@ -337,7 +337,7 @@ private sealed class SingleRedisResult : RedisResult
...
@@ -337,7 +337,7 @@ private sealed class SingleRedisResult : RedisResult
{
{
private
readonly
RedisValue
_value
;
private
readonly
RedisValue
_value
;
private
readonly
ResultType
_resultType
;
private
readonly
ResultType
_resultType
;
public
override
ResultType
Result
Type
=>
_resultType
;
public
override
ResultType
Type
=>
_resultType
;
public
SingleRedisResult
(
RedisValue
value
,
ResultType
?
resultType
)
public
SingleRedisResult
(
RedisValue
value
,
ResultType
?
resultType
)
{
{
_value
=
value
;
_value
=
value
;
...
...
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
View file @
18d14db3
...
@@ -762,5 +762,33 @@ public static RedisValue CreateFrom(MemoryStream stream)
...
@@ -762,5 +762,33 @@ public static RedisValue CreateFrom(MemoryStream stream)
return
stream
.
ToArray
();
return
stream
.
ToArray
();
}
}
}
}
/// <summary>
/// Indicates whether the current value has the supplied value as a prefix
/// </summary>
public
bool
StartsWith
(
RedisValue
value
)
{
ReadOnlyMemory
<
byte
>
rawThis
,
rawOther
;
var
thisType
=
this
.
Type
;
if
(
thisType
==
value
.
Type
)
// same? can often optimize
{
switch
(
thisType
)
{
case
StorageType
.
String
:
var
sThis
=
((
string
)
this
.
_objectOrSentinel
);
var
sOther
=
((
string
)
value
.
_objectOrSentinel
);
return
sThis
.
StartsWith
(
sOther
,
StringComparison
.
Ordinal
);
case
StorageType
.
Raw
:
rawThis
=
this
.
_memory
;
rawOther
=
value
.
_memory
;
return
rawThis
.
Span
.
StartsWith
(
rawOther
.
Span
);
}
}
rawThis
=
(
ReadOnlyMemory
<
byte
>)
this
;
rawOther
=
(
ReadOnlyMemory
<
byte
>)
value
;
return
rawThis
.
Span
.
StartsWith
(
rawOther
.
Span
);
}
}
}
}
}
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