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
0376026f
Commit
0376026f
authored
Sep 25, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better null vs empty key prefix handling
parent
d9fa8e5e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
8 deletions
+54
-8
WithKeyPrefixTests.cs
StackExchange.Redis.Tests/WithKeyPrefixTests.cs
+48
-7
DatabaseExtension.cs
...tackExchange/Redis/KeyspaceIsolation/DatabaseExtension.cs
+6
-1
No files found.
StackExchange.Redis.Tests/WithKeyPrefixTests.cs
View file @
0376026f
...
...
@@ -8,6 +8,54 @@ namespace StackExchange.Redis.Tests
[
TestFixture
]
public
class
WithKeyPrefixTests
:
TestBase
{
[
Test
]
public
void
BlankPrefixYieldsSame_Bytes
()
{
using
(
var
conn
=
Create
())
{
var
raw
=
conn
.
GetDatabase
(
1
);
var
prefixed
=
raw
.
WithKeyPrefix
(
new
byte
[
0
]);
Assert
.
AreSame
(
raw
,
prefixed
);
}
}
[
Test
]
public
void
BlankPrefixYieldsSame_String
()
{
using
(
var
conn
=
Create
())
{
var
raw
=
conn
.
GetDatabase
(
1
);
var
prefixed
=
raw
.
WithKeyPrefix
(
""
);
Assert
.
AreSame
(
raw
,
prefixed
);
}
}
[
Test
,
ExpectedException
(
typeof
(
ArgumentNullException
))]
public
void
NullPrefixIsError_Bytes
()
{
using
(
var
conn
=
Create
())
{
var
raw
=
conn
.
GetDatabase
(
1
);
var
prefixed
=
raw
.
WithKeyPrefix
((
string
)
null
);
}
}
[
Test
,
ExpectedException
(
typeof
(
ArgumentNullException
))]
public
void
NullPrefixIsError_String
()
{
using
(
var
conn
=
Create
())
{
var
raw
=
conn
.
GetDatabase
(
1
);
var
prefixed
=
raw
.
WithKeyPrefix
((
string
)
null
);
}
}
[
Test
,
ExpectedException
(
typeof
(
ArgumentNullException
))]
[
TestCase
(
"abc"
)]
[
TestCase
(
""
)]
[
TestCase
(
null
)]
public
void
NullDatabaseIsError
(
string
prefix
)
{
IDatabase
raw
=
null
;
var
prefixed
=
raw
.
WithKeyPrefix
(
prefix
);
}
[
Test
]
public
void
BasicSmokeTest
()
{
...
...
@@ -15,13 +63,6 @@ public void BasicSmokeTest()
{
var
raw
=
conn
.
GetDatabase
(
1
);
var
vanilla
=
raw
.
WithKeyPrefix
(
""
);
Assert
.
AreSame
(
raw
,
vanilla
);
vanilla
=
raw
.
WithKeyPrefix
((
byte
[])
null
);
Assert
.
AreSame
(
raw
,
vanilla
);
vanilla
=
raw
.
WithKeyPrefix
((
string
)
null
);
Assert
.
AreSame
(
raw
,
vanilla
);
var
foo
=
raw
.
WithKeyPrefix
(
"foo"
);
var
foobar
=
foo
.
WithKeyPrefix
(
"bar"
);
...
...
StackExchange.Redis/StackExchange/Redis/KeyspaceIsolation/DatabaseExtension.cs
View file @
0376026f
...
...
@@ -44,7 +44,12 @@ public static IDatabase WithKeyPrefix(this IDatabase database, RedisKey keyPrefi
throw
new
ArgumentNullException
(
"database"
);
}
if
(
keyPrefix
.
IsNull
||
keyPrefix
.
Value
.
Length
==
0
)
if
(
keyPrefix
.
IsNull
)
{
throw
new
ArgumentNullException
(
"keyPrefix"
);
}
if
(
keyPrefix
.
Value
.
Length
==
0
)
{
return
database
;
// fine - you can keep using the original, then
}
...
...
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