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
15ebc8ab
Commit
15ebc8ab
authored
Jul 10, 2018
by
Marc Gravell
Committed by
Nick Craver
Jul 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
skip rather than fail if dedicated database isn't available
parent
da0ffb62
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
37 additions
and
18 deletions
+37
-18
Massive Delete.cs
...kExchange.Redis.Tests/Booksleeve/Issues/Massive Delete.cs
+1
-0
Databases.cs
StackExchange.Redis.Tests/Databases.cs
+7
-3
Skip.cs
StackExchange.Redis.Tests/Helpers/Skip.cs
+6
-0
TestConfig.cs
StackExchange.Redis.Tests/Helpers/TestConfig.cs
+6
-1
Keys.cs
StackExchange.Redis.Tests/Keys.cs
+2
-1
Scans.cs
StackExchange.Redis.Tests/Scans.cs
+3
-3
IServer.cs
...kExchange.Redis/StackExchange/Redis/Interfaces/IServer.cs
+5
-0
RedisServer.cs
StackExchange.Redis/StackExchange/Redis/RedisServer.cs
+2
-0
Program.cs
TestConsole/Program.cs
+5
-10
No files found.
StackExchange.Redis.Tests/Booksleeve/Issues/Massive Delete.cs
View file @
15ebc8ab
...
...
@@ -15,6 +15,7 @@ private void Prep(int db, string key)
var
prefix
=
Me
();
using
(
var
muxer
=
GetUnsecuredConnection
(
allowAdmin
:
true
))
{
Skip
.
IfMissingDatabase
(
muxer
,
db
);
GetServer
(
muxer
).
FlushDatabase
(
db
);
Task
last
=
null
;
var
conn
=
muxer
.
GetDatabase
(
db
);
...
...
StackExchange.Redis.Tests/Databases.cs
View file @
15ebc8ab
...
...
@@ -15,12 +15,16 @@ public async Task CountKeys()
var
db2Id
=
TestConfig
.
GetDedicatedDB
();
using
(
var
muxer
=
Create
(
allowAdmin
:
true
))
{
Skip
.
IfMissingDatabase
(
muxer
,
db1Id
);
Skip
.
IfMissingDatabase
(
muxer
,
db2Id
);
var
server
=
GetAnyMaster
(
muxer
);
server
.
FlushDatabase
(
db1Id
,
CommandFlags
.
FireAndForget
);
server
.
FlushDatabase
(
db2Id
,
CommandFlags
.
FireAndForget
);
}
using
(
var
muxer
=
Create
())
{
Skip
.
IfMissingDatabase
(
muxer
,
db1Id
);
Skip
.
IfMissingDatabase
(
muxer
,
db2Id
);
RedisKey
key
=
Me
();
var
db61
=
muxer
.
GetDatabase
(
db1Id
);
var
db62
=
muxer
.
GetDatabase
(
db2Id
);
...
...
@@ -43,9 +47,9 @@ public void MultiDatabases()
using
(
var
muxer
=
Create
())
{
RedisKey
key
=
Me
();
var
db0
=
muxer
.
GetDatabase
(
TestConfig
.
GetDedicatedDB
());
var
db1
=
muxer
.
GetDatabase
(
TestConfig
.
GetDedicatedDB
());
var
db2
=
muxer
.
GetDatabase
(
TestConfig
.
GetDedicatedDB
());
var
db0
=
muxer
.
GetDatabase
(
TestConfig
.
GetDedicatedDB
(
muxer
));
var
db1
=
muxer
.
GetDatabase
(
TestConfig
.
GetDedicatedDB
(
muxer
));
var
db2
=
muxer
.
GetDatabase
(
TestConfig
.
GetDedicatedDB
(
muxer
));
db0
.
Ping
();
db0
.
KeyDelete
(
key
,
CommandFlags
.
FireAndForget
);
...
...
StackExchange.Redis.Tests/Helpers/Skip.cs
View file @
15ebc8ab
...
...
@@ -34,6 +34,12 @@ public static void IfMissingFeature(ConnectionMultiplexer conn, string feature,
};
}
}
internal
static
void
IfMissingDatabase
(
ConnectionMultiplexer
conn
,
int
dbId
)
{
var
dbCount
=
conn
.
GetServer
(
conn
.
GetEndPoints
()[
0
]).
DatabaseCount
;
if
(
dbId
>=
dbCount
)
throw
new
SkipTestException
(
$"Database
{
dbId
}
is not supported on this server."
);
}
}
#pragma warning disable RCS1194 // Implement exception constructors.
...
...
StackExchange.Redis.Tests/Helpers/TestConfig.cs
View file @
15ebc8ab
...
...
@@ -12,7 +12,12 @@ public static class TestConfig
public
static
Config
Current
{
get
;
}
private
static
int
_db
=
17
;
public
static
int
GetDedicatedDB
()
=>
Interlocked
.
Increment
(
ref
_db
);
public
static
int
GetDedicatedDB
(
ConnectionMultiplexer
conn
=
null
)
{
int
db
=
Interlocked
.
Increment
(
ref
_db
);
if
(
conn
!=
null
)
Skip
.
IfMissingDatabase
(
conn
,
db
);
return
db
;
}
static
TestConfig
()
{
...
...
StackExchange.Redis.Tests/Keys.cs
View file @
15ebc8ab
...
...
@@ -34,7 +34,8 @@ public void FlushFetchRandomKey()
{
using
(
var
conn
=
Create
(
allowAdmin
:
true
))
{
var
dbId
=
TestConfig
.
GetDedicatedDB
();
var
dbId
=
TestConfig
.
GetDedicatedDB
(
conn
);
Skip
.
IfMissingDatabase
(
conn
,
dbId
);
var
db
=
conn
.
GetDatabase
(
dbId
);
var
prefix
=
Me
();
conn
.
GetServer
(
TestConfig
.
Current
.
MasterServerAndPort
).
FlushDatabase
(
dbId
);
...
...
StackExchange.Redis.Tests/Scans.cs
View file @
15ebc8ab
...
...
@@ -18,7 +18,7 @@ public void KeysScan(bool supported)
string
[]
disabledCommands
=
supported
?
null
:
new
[]
{
"scan"
};
using
(
var
conn
=
Create
(
disabledCommands
:
disabledCommands
,
allowAdmin
:
true
))
{
var
dbId
=
TestConfig
.
GetDedicatedDB
();
var
dbId
=
TestConfig
.
GetDedicatedDB
(
conn
);
var
db
=
conn
.
GetDatabase
(
dbId
);
var
prefix
=
Me
()
+
":"
;
var
server
=
GetServer
(
conn
);
...
...
@@ -44,7 +44,7 @@ public void ScansIScanning()
using
(
var
conn
=
Create
(
allowAdmin
:
true
))
{
var
prefix
=
Me
()
+
Guid
.
NewGuid
();
var
dbId
=
TestConfig
.
GetDedicatedDB
();
var
dbId
=
TestConfig
.
GetDedicatedDB
(
conn
);
var
db
=
conn
.
GetDatabase
(
dbId
);
var
server
=
GetServer
(
conn
);
server
.
FlushDatabase
(
dbId
);
...
...
@@ -93,7 +93,7 @@ public void ScanResume()
{
// only goes up to 3.*, so...
Skip
.
IfMissingFeature
(
conn
,
nameof
(
RedisFeatures
.
Scan
),
x
=>
x
.
Scan
);
var
dbId
=
TestConfig
.
GetDedicatedDB
();
var
dbId
=
TestConfig
.
GetDedicatedDB
(
conn
);
var
db
=
conn
.
GetDatabase
(
dbId
);
var
prefix
=
Me
();
var
server
=
GetServer
(
conn
);
...
...
StackExchange.Redis/StackExchange/Redis/Interfaces/IServer.cs
View file @
15ebc8ab
...
...
@@ -52,6 +52,11 @@ public partial interface IServer : IRedis
/// </summary>
Version
Version
{
get
;
}
/// <summary>
/// The number of databases supported on this server
/// </summary>
int
DatabaseCount
{
get
;
}
/// <summary>
/// The CLIENT KILL command closes a given client connection identified by ip:port.
/// The ip:port should match a line returned by the CLIENT LIST command.
...
...
StackExchange.Redis/StackExchange/Redis/RedisServer.cs
View file @
15ebc8ab
...
...
@@ -18,6 +18,8 @@ internal RedisServer(ConnectionMultiplexer multiplexer, ServerEndPoint server, o
this
.
server
=
server
??
throw
new
ArgumentNullException
(
nameof
(
server
));
}
int
IServer
.
DatabaseCount
=>
server
.
Databases
;
public
ClusterConfiguration
ClusterConfiguration
=>
server
.
ClusterConfiguration
;
public
EndPoint
EndPoint
=>
server
.
EndPoint
;
...
...
TestConsole/Program.cs
View file @
15ebc8ab
...
...
@@ -13,20 +13,15 @@ private static int Main()
var
watch
=
Stopwatch
.
StartNew
();
try
{
#if DEBUG
// Pipelines.Sockets.Unofficial.DebugCounters.SetLog(Console.Out);
#endif
var
config
=
new
ConfigurationOptions
{
ConnectRetry
=
0
,
EndPoints
=
{
"127.0.0.1:6381"
},
Password
=
"abc"
,
EndPoints
=
{
"127.0.0.1:6379"
},
};
using
(
var
conn
=
ConnectionMultiplexer
.
Connect
(
config
,
log
:
null
))
using
(
var
conn
=
ConnectionMultiplexer
.
Connect
(
config
,
log
:
Console
.
Out
))
{
//Execute(conn);
Execute
(
conn
);
}
return
0
;
...
...
@@ -46,14 +41,14 @@ private static int Main()
private
static
void
Execute
(
ConnectionMultiplexer
conn
)
{
Console
.
WriteLine
(
"Executing..."
);
var
key
=
"abc"
;
Console
.
ReadKey
();
var
db
=
conn
.
GetDatabase
(
0
);
var
t
=
db
.
CreateTransaction
();
t
.
HashSetAsync
(
key
,
"foo"
,
"bar"
);
t
.
KeyExpireAsync
(
key
,
TimeSpan
.
FromSeconds
(
3600
));
t
.
Execute
();
Console
.
ReadKey
(
);
Console
.
WriteLine
(
"Done"
);
}
}
}
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