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
234ff979
Commit
234ff979
authored
Jul 09, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #535 - implement Execute/ExecuteAsync on IServer
parent
6e9f3db6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
115 additions
and
2 deletions
+115
-2
Execute.cs
StackExchange.Redis.Tests/Execute.cs
+43
-0
IDatabase.cs
...xchange.Redis/StackExchange/Redis/Interfaces/IDatabase.cs
+2
-0
IDatabaseAsync.cs
...ge.Redis/StackExchange/Redis/Interfaces/IDatabaseAsync.cs
+2
-0
IServer.cs
...kExchange.Redis/StackExchange/Redis/Interfaces/IServer.cs
+46
-0
Message.cs
StackExchange.Redis/StackExchange/Redis/Message.cs
+5
-1
RedisDatabase.cs
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
+1
-1
RedisServer.cs
StackExchange.Redis/StackExchange/Redis/RedisServer.cs
+16
-0
No files found.
StackExchange.Redis.Tests/Execute.cs
0 → 100644
View file @
234ff979
using
System.Linq
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit.Abstractions
;
namespace
StackExchange.Redis.Tests
{
public
class
ExecuteTests
:
TestBase
{
public
ExecuteTests
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
[
Fact
]
public
async
Task
DBExecute
()
{
using
(
var
conn
=
Create
())
{
var
db
=
conn
.
GetDatabase
(
4
);
RedisKey
key
=
Me
();
db
.
StringSet
(
key
,
"some value"
);
var
actual
=
(
string
)
db
.
Execute
(
"GET"
,
key
);
Assert
.
Equal
(
"some value"
,
actual
);
actual
=
(
string
)
await
db
.
ExecuteAsync
(
"GET"
,
key
);
Assert
.
Equal
(
"some value"
,
actual
);
}
}
[
Fact
]
public
async
Task
ServerExecute
()
{
using
(
var
conn
=
Create
())
{
var
server
=
conn
.
GetServer
(
conn
.
GetEndPoints
().
First
());
var
actual
=
(
string
)
server
.
Execute
(
"echo"
,
"some value"
);
Assert
.
Equal
(
"some value"
,
actual
);
actual
=
(
string
)
await
server
.
ExecuteAsync
(
"echo"
,
"some value"
);
Assert
.
Equal
(
"some value"
,
actual
);
}
}
}
}
StackExchange.Redis/StackExchange/Redis/Interfaces/IDatabase.cs
View file @
234ff979
...
...
@@ -795,6 +795,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// </summary>
/// <param name="command">The command to run.</param>
/// <param name="args">The arguments to pass for the command.</param>
/// <remarks>This API should be considered an advanced feature; inappropriate use can be harmful</remarks>
/// <returns>A dynamic representation of the command's result</returns>
RedisResult
Execute
(
string
command
,
params
object
[]
args
);
...
...
@@ -806,6 +807,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <param name="command">The command to run.</param>
/// <param name="args">The arguments to pass for the command.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <remarks>This API should be considered an advanced feature; inappropriate use can be harmful</remarks>
/// <returns>A dynamic representation of the command's result</returns>
RedisResult
Execute
(
string
command
,
ICollection
<
object
>
args
,
CommandFlags
flags
=
CommandFlags
.
None
);
...
...
StackExchange.Redis/StackExchange/Redis/Interfaces/IDatabaseAsync.cs
View file @
234ff979
...
...
@@ -758,6 +758,7 @@ public interface IDatabaseAsync : IRedisAsync
/// </summary>
/// <param name="command">The command to run.</param>
/// <param name="args">The arguments to pass for the command.</param>
/// <remarks>This API should be considered an advanced feature; inappropriate use can be harmful</remarks>
/// <returns>A dynamic representation of the command's result</returns>
Task
<
RedisResult
>
ExecuteAsync
(
string
command
,
params
object
[]
args
);
...
...
@@ -769,6 +770,7 @@ public interface IDatabaseAsync : IRedisAsync
/// <param name="command">The command to run.</param>
/// <param name="args">The arguments to pass for the command.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <remarks>This API should be considered an advanced feature; inappropriate use can be harmful</remarks>
/// <returns>A dynamic representation of the command's result</returns>
Task
<
RedisResult
>
ExecuteAsync
(
string
command
,
ICollection
<
object
>
args
,
CommandFlags
flags
=
CommandFlags
.
None
);
...
...
StackExchange.Redis/StackExchange/Redis/Interfaces/IServer.cs
View file @
234ff979
...
...
@@ -230,6 +230,52 @@ public partial interface IServer : IRedis
/// <remarks>https://redis.io/commands/echo</remarks>
Task
<
RedisValue
>
EchoAsync
(
RedisValue
message
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Execute an arbitrary command against the server; this is primarily intended for
/// executing modules, but may also be used to provide access to new features that lack
/// a direct API.
/// </summary>
/// <param name="command">The command to run.</param>
/// <param name="args">The arguments to pass for the command.</param>
/// <remarks>This API should be considered an advanced feature; inappropriate use can be harmful</remarks>
/// <returns>A dynamic representation of the command's result</returns>
RedisResult
Execute
(
string
command
,
params
object
[]
args
);
/// <summary>
/// Execute an arbitrary command against the server; this is primarily intended for
/// executing modules, but may also be used to provide access to new features that lack
/// a direct API.
/// </summary>
/// <param name="command">The command to run.</param>
/// <param name="args">The arguments to pass for the command.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <remarks>This API should be considered an advanced feature; inappropriate use can be harmful</remarks>
/// <returns>A dynamic representation of the command's result</returns>
RedisResult
Execute
(
string
command
,
ICollection
<
object
>
args
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Execute an arbitrary command against the server; this is primarily intended for
/// executing modules, but may also be used to provide access to new features that lack
/// a direct API.
/// </summary>
/// <param name="command">The command to run.</param>
/// <param name="args">The arguments to pass for the command.</param>
/// <remarks>This API should be considered an advanced feature; inappropriate use can be harmful</remarks>
/// <returns>A dynamic representation of the command's result</returns>
Task
<
RedisResult
>
ExecuteAsync
(
string
command
,
params
object
[]
args
);
/// <summary>
/// Execute an arbitrary command against the server; this is primarily intended for
/// executing modules, but may also be used to provide access to new features that lack
/// a direct API.
/// </summary>
/// <param name="command">The command to run.</param>
/// <param name="args">The arguments to pass for the command.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <remarks>This API should be considered an advanced feature; inappropriate use can be harmful</remarks>
/// <returns>A dynamic representation of the command's result</returns>
Task
<
RedisResult
>
ExecuteAsync
(
string
command
,
ICollection
<
object
>
args
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Delete all the keys of all databases on the server.
/// </summary>
...
...
StackExchange.Redis/StackExchange/Redis/Message.cs
View file @
234ff979
...
...
@@ -85,7 +85,11 @@ internal abstract class Message : ICompletable
protected
Message
(
int
db
,
CommandFlags
flags
,
RedisCommand
command
)
{
bool
dbNeeded
=
RequiresDatabase
(
command
);
if
(
db
<
0
)
if
(
command
==
RedisCommand
.
UNKNOWN
)
{
// all bets are off here
}
else
if
(
db
<
0
)
{
if
(
dbNeeded
)
{
...
...
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
View file @
234ff979
...
...
@@ -3207,7 +3207,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
}
}
private
sealed
class
ExecuteMessage
:
Message
internal
sealed
class
ExecuteMessage
:
Message
{
private
readonly
string
_command
;
private
readonly
ICollection
<
object
>
args
;
...
...
StackExchange.Redis/StackExchange/Redis/RedisServer.cs
View file @
234ff979
...
...
@@ -824,6 +824,22 @@ public Task SentinelFailoverAsync(string serviceName, CommandFlags flags = Comma
return
ExecuteAsync
(
msg
,
ResultProcessor
.
SentinelArrayOfArrays
);
}
public
RedisResult
Execute
(
string
command
,
params
object
[]
args
)
=>
Execute
(
command
,
args
,
CommandFlags
.
None
);
public
RedisResult
Execute
(
string
command
,
ICollection
<
object
>
args
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
new
RedisDatabase
.
ExecuteMessage
(-
1
,
flags
,
command
,
args
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
ScriptResult
);
}
public
Task
<
RedisResult
>
ExecuteAsync
(
string
command
,
params
object
[]
args
)
=>
ExecuteAsync
(
command
,
args
,
CommandFlags
.
None
);
public
Task
<
RedisResult
>
ExecuteAsync
(
string
command
,
ICollection
<
object
>
args
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
new
RedisDatabase
.
ExecuteMessage
(-
1
,
flags
,
command
,
args
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
ScriptResult
);
}
#
endregion
}
}
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