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
072a20b1
Commit
072a20b1
authored
Sep 04, 2019
by
mgravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
random ideas
parent
4eff7c92
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
116 additions
and
0 deletions
+116
-0
IExecutor.cs
src/StackExchange.Redis/Interfaces/IExecutor.cs
+116
-0
No files found.
src/StackExchange.Redis/Interfaces/IExecutor.cs
0 → 100644
View file @
072a20b1
using
System
;
using
System.Runtime.CompilerServices
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
StackExchange.Redis.Interfaces
{
internal
interface
IExecutor
{
ValueTask
<
TResult
>
ExecuteAsync
<
TCommand
,
TResult
>(
TCommand
command
,
IResultParser
<
TResult
>
parser
,
CommandOptions
options
=
default
)
where
TCommand
:
ICommand
;
}
internal
static
class
ExecutorExtensions
{
public
static
ValueTask
<
RedisResult
>
ExecuteAsync
<
TCommand
>(
this
IExecutor
executor
,
TCommand
command
,
CommandOptions
options
=
default
)
where
TCommand
:
ICommand
=>
executor
.
ExecuteAsync
<
TCommand
,
RedisResult
>(
command
,
ResultParser
.
RedisResult
,
options
);
}
internal
interface
IDbFoo
:
IExecutor
{
int
Database
{
get
;
}
RedisKey
KeyPrefix
{
get
;
}
}
internal
static
class
StringCommands
{
public
static
ValueTask
<
RedisValue
>
StringGetAsync
(
IDbFoo
database
,
RedisKey
key
,
CommandOptions
options
=
default
)
=>
database
.
ExecuteAsync
(
Command
.
Create
(
key
),
ResultParser
.
RedisValue
,
options
);
}
internal
static
class
ListCommands
{
public
static
ValueTask
<
Lease
<
RedisValue
>>
ListRangeAsync
(
IDbFoo
database
,
RedisKey
key
,
Range
range
=
default
,
CommandOptions
options
=
default
)
=>
database
.
ExecuteAsync
(
Command
.
Create
(
key
),
ResultParser
.
LeaseRedisValue
,
options
);
}
static
class
Command
{
internal
static
KeyCommand
Create
(
RedisKey
key
)
=>
throw
new
NotImplementedException
();
}
readonly
struct
KeyCommand
:
ICommand
{
}
internal
interface
ICommand
{
}
internal
static
class
ResultParser
{
public
static
IResultParser
<
RedisResult
>
RedisResult
=>
throw
new
NotImplementedException
();
public
static
IResultParser
<
RedisValue
>
RedisValue
=>
throw
new
NotImplementedException
();
public
static
IResultParser
<
Lease
<
RedisValue
>>
LeaseRedisValue
=>
throw
new
NotImplementedException
();
}
internal
readonly
struct
Lease
<
T
>
:
IDisposable
{
internal
Lease
(
Memory
<
T
>
memory
,
Action
<
Memory
<
T
>>
onDispose
)
{
Memory
=
memory
;
_onDispose
=
onDispose
;
}
public
Memory
<
T
>
Memory
{
get
;
}
private
readonly
Action
<
Memory
<
T
>>
_onDispose
;
public
Span
<
T
>
Span
=>
Memory
.
Span
;
public
void
Dispose
()
=>
_onDispose
?.
Invoke
(
Memory
);
}
interface
IResultParser
<
TResult
>
{
TResult
Parse
(
RawResult
result
);
}
internal
readonly
struct
CommandOptions
{
public
CommandFlags
CommandFlags
{
get
;
}
public
int
Database
{
get
;
}
public
CancellationToken
CancellationToken
{
get
;
}
public
RedisKey
KeyPrefix
{
get
;
}
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
public
CommandOptions
With
(
in
RedisKey
keyPrefix
)
=>
new
CommandOptions
(
in
this
,
in
keyPrefix
);
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
public
CommandOptions
With
(
CommandFlags
commandFlags
)
=>
new
CommandOptions
(
in
this
,
commandFlags
);
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
public
CommandOptions
With
(
in
CancellationToken
cancellationToken
)
=>
new
CommandOptions
(
in
this
,
in
cancellationToken
);
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
private
CommandOptions
(
in
CommandOptions
value
,
in
CancellationToken
cancellationToken
)
{
if
(
value
.
CancellationToken
.
CanBeCanceled
)
ThrowInvalidOperation
();
this
=
value
;
CancellationToken
=
cancellationToken
;
}
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
private
CommandOptions
(
in
CommandOptions
value
,
CommandFlags
commandFlags
)
{
if
(
value
.
CommandFlags
!=
0
)
ThrowInvalidOperation
();
this
=
value
;
CommandFlags
=
commandFlags
;
}
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
private
CommandOptions
(
in
CommandOptions
value
,
in
RedisKey
keyPrefix
)
{
if
(!
value
.
KeyPrefix
.
IsNull
)
ThrowInvalidOperation
();
this
=
value
;
KeyPrefix
=
keyPrefix
;
}
[
MethodImpl
(
MethodImplOptions
.
NoInlining
)]
private
static
void
ThrowInvalidOperation
()
=>
throw
new
InvalidOperationException
();
}
}
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