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
22c4c1ce
Commit
22c4c1ce
authored
Aug 15, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
General cleanup
parent
53c43581
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
60 deletions
+68
-60
AggresssiveTests.cs
StackExchange.Redis.Tests/AggresssiveTests.cs
+30
-23
Parse.cs
StackExchange.Redis.Tests/Parse.cs
+4
-6
Streams.cs
StackExchange.Redis.Tests/Streams.cs
+16
-16
TestBase.cs
StackExchange.Redis.Tests/TestBase.cs
+0
-2
IProfiledCommand.cs
StackExchange.Redis/Profiling/IProfiledCommand.cs
+8
-7
Program.cs
TestConsole/Program.cs
+10
-6
No files found.
StackExchange.Redis.Tests/AggresssiveTests.cs
View file @
22c4c1ce
...
...
@@ -25,7 +25,7 @@ public async Task ParallelTransactionsWithConditions()
RedisKey
hits
=
Me
(),
trigger
=
Me
()
+
"3"
;
int
expectedSuccess
=
0
;
await
muxers
[
0
].
GetDatabase
().
KeyDeleteAsync
(
new
[]
{
hits
,
trigger
});
await
muxers
[
0
].
GetDatabase
().
KeyDeleteAsync
(
new
[]
{
hits
,
trigger
})
.
ForAwait
()
;
Task
[]
tasks
=
new
Task
[
Workers
];
for
(
int
i
=
0
;
i
<
tasks
.
Length
;
i
++)
...
...
@@ -36,12 +36,12 @@ public async Task ParallelTransactionsWithConditions()
{
for
(
int
j
=
0
;
j
<
PerThread
;
j
++)
{
var
oldVal
=
await
scopedDb
.
StringGetAsync
(
trigger
);
var
oldVal
=
await
scopedDb
.
StringGetAsync
(
trigger
)
.
ForAwait
()
;
var
tran
=
scopedDb
.
CreateTransaction
();
tran
.
AddCondition
(
Condition
.
StringEqual
(
trigger
,
oldVal
));
var
x
=
tran
.
StringIncrementAsync
(
trigger
);
var
y
=
tran
.
StringIncrementAsync
(
hits
);
if
(
await
tran
.
ExecuteAsync
())
if
(
await
tran
.
ExecuteAsync
()
.
ForAwait
()
)
{
Interlocked
.
Increment
(
ref
expectedSuccess
);
await
x
;
...
...
@@ -49,8 +49,8 @@ public async Task ParallelTransactionsWithConditions()
}
else
{
await
Assert
.
ThrowsAsync
<
TaskCanceledException
>(()
=>
x
);
await
Assert
.
ThrowsAsync
<
TaskCanceledException
>(()
=>
y
);
await
Assert
.
ThrowsAsync
<
TaskCanceledException
>(()
=>
x
)
.
ForAwait
()
;
await
Assert
.
ThrowsAsync
<
TaskCanceledException
>(()
=>
y
)
.
ForAwait
()
;
}
}
});
...
...
@@ -59,7 +59,7 @@ public async Task ParallelTransactionsWithConditions()
{
await
tasks
[
i
];
}
var
actual
=
(
int
)
await
muxers
[
0
].
GetDatabase
().
StringGetAsync
(
hits
);
var
actual
=
(
int
)
await
muxers
[
0
].
GetDatabase
().
StringGetAsync
(
hits
)
.
ForAwait
()
;
Assert
.
Equal
(
expectedSuccess
,
actual
);
Writer
.
WriteLine
(
$"success:
{
actual
}
out of
{
Workers
*
PerThread
}
attempts"
);
}
...
...
@@ -81,10 +81,14 @@ public void RunCompetingBatchesOnSameMuxer()
{
var
db
=
muxer
.
GetDatabase
();
Thread
x
=
new
Thread
(
state
=>
BatchRunPings
((
IDatabase
)
state
));
x
.
Name
=
nameof
(
BatchRunPings
);
Thread
y
=
new
Thread
(
state
=>
BatchRunIntegers
((
IDatabase
)
state
));
y
.
Name
=
nameof
(
BatchRunIntegers
);
Thread
x
=
new
Thread
(
state
=>
BatchRunPings
((
IDatabase
)
state
))
{
Name
=
nameof
(
BatchRunPings
)
};
Thread
y
=
new
Thread
(
state
=>
BatchRunIntegers
((
IDatabase
)
state
))
{
Name
=
nameof
(
BatchRunIntegers
)
};
x
.
Start
(
db
);
y
.
Start
(
db
);
...
...
@@ -151,8 +155,8 @@ public async Task RunCompetingBatchesOnSameMuxerAsync()
private
async
Task
BatchRunIntegersAsync
(
IDatabase
db
)
{
var
key
=
Me
();
await
db
.
KeyDeleteAsync
(
key
);
await
db
.
StringSetAsync
(
key
,
1
);
await
db
.
KeyDeleteAsync
(
key
)
.
ForAwait
()
;
await
db
.
StringSetAsync
(
key
,
1
)
.
ForAwait
()
;
Task
[]
tasks
=
new
Task
[
InnerCount
];
for
(
int
i
=
0
;
i
<
IterationCount
;
i
++)
{
...
...
@@ -168,7 +172,7 @@ private async Task BatchRunIntegersAsync(IDatabase db)
}
}
var
count
=
(
long
)
await
db
.
StringGetAsync
(
key
);
var
count
=
(
long
)
await
db
.
StringGetAsync
(
key
)
.
ForAwait
()
;
Writer
.
WriteLine
(
$"tally:
{
count
}
"
);
}
...
...
@@ -197,10 +201,14 @@ public void RunCompetingTransactionsOnSameMuxer()
{
var
db
=
muxer
.
GetDatabase
();
Thread
x
=
new
Thread
(
state
=>
TranRunPings
((
IDatabase
)
state
));
x
.
Name
=
nameof
(
BatchRunPings
);
Thread
y
=
new
Thread
(
state
=>
TranRunIntegers
((
IDatabase
)
state
));
y
.
Name
=
nameof
(
BatchRunIntegers
);
Thread
x
=
new
Thread
(
state
=>
TranRunPings
((
IDatabase
)
state
))
{
Name
=
nameof
(
BatchRunPings
)
};
Thread
y
=
new
Thread
(
state
=>
TranRunIntegers
((
IDatabase
)
state
))
{
Name
=
nameof
(
BatchRunIntegers
)
};
x
.
Start
(
db
);
y
.
Start
(
db
);
...
...
@@ -271,8 +279,8 @@ public async Task RunCompetingTransactionsOnSameMuxerAsync()
private
async
Task
TranRunIntegersAsync
(
IDatabase
db
)
{
var
key
=
Me
();
await
db
.
KeyDeleteAsync
(
key
);
await
db
.
StringSetAsync
(
key
,
1
);
await
db
.
KeyDeleteAsync
(
key
)
.
ForAwait
()
;
await
db
.
StringSetAsync
(
key
,
1
)
.
ForAwait
()
;
Task
[]
tasks
=
new
Task
[
InnerCount
];
for
(
int
i
=
0
;
i
<
IterationCount
;
i
++)
{
...
...
@@ -282,15 +290,14 @@ private async Task TranRunIntegersAsync(IDatabase db)
{
tasks
[
j
]
=
batch
.
StringIncrementAsync
(
key
);
}
await
batch
.
ExecuteAsync
();
await
batch
.
ExecuteAsync
()
.
ForAwait
()
;
for
(
int
j
=
tasks
.
Length
-
1
;
j
>=
0
;
j
--)
{
await
tasks
[
j
];
}
}
var
count
=
(
long
)
await
db
.
StringGetAsync
(
key
);
var
count
=
(
long
)
await
db
.
StringGetAsync
(
key
).
ForAwait
();
Writer
.
WriteLine
(
$"tally:
{
count
}
"
);
}
...
...
@@ -307,7 +314,7 @@ private async Task TranRunPingsAsync(IDatabase db)
{
tasks
[
j
]
=
batch
.
PingAsync
();
}
await
batch
.
ExecuteAsync
();
await
batch
.
ExecuteAsync
()
.
ForAwait
()
;
for
(
int
j
=
tasks
.
Length
-
1
;
j
>=
0
;
j
--)
{
await
tasks
[
j
];
...
...
StackExchange.Redis.Tests/Parse.cs
View file @
22c4c1ce
...
...
@@ -28,6 +28,7 @@ public static IEnumerable<object[]> GetTestData()
yield
return
new
object
[]
{
"$4\r\nPING\r\n$4\r\nPONG\r\n$4\r\nPONG\r\n"
,
3
};
yield
return
new
object
[]
{
"$4\r\nPING\r\n$4\r\nPONG\r\n$4\r\nPONG\r\n$"
,
3
};
}
[
Theory
]
[
MemberData
(
nameof
(
GetTestData
))]
public
void
ParseAsSingleChunk
(
string
ascii
,
int
expected
)
...
...
@@ -36,7 +37,6 @@ public void ParseAsSingleChunk(string ascii, int expected)
ProcessMessages
(
buffer
,
expected
);
}
[
Theory
]
[
MemberData
(
nameof
(
GetTestData
))]
public
void
ParseAsLotsOfChunks
(
string
ascii
,
int
expected
)
...
...
@@ -59,10 +59,9 @@ public void ParseAsLotsOfChunks(string ascii, int expected)
var
buffer
=
new
ReadOnlySequence
<
byte
>(
chain
,
0
,
tail
,
1
);
Assert
.
Equal
(
bytes
.
Length
,
buffer
.
Length
);
ProcessMessages
(
buffer
,
expected
);
}
void
ProcessMessages
(
ReadOnlySequence
<
byte
>
buffer
,
int
expected
)
private
void
ProcessMessages
(
ReadOnlySequence
<
byte
>
buffer
,
int
expected
)
{
Writer
.
WriteLine
(
$"chain:
{
buffer
.
Length
}
"
);
var
reader
=
new
BufferReader
(
buffer
);
...
...
@@ -76,8 +75,7 @@ void ProcessMessages(ReadOnlySequence<byte> buffer, int expected)
Assert
.
Equal
(
expected
,
found
);
}
class
FragmentedSegment
<
T
>
:
ReadOnlySequenceSegment
<
T
>
private
class
FragmentedSegment
<
T
>
:
ReadOnlySequenceSegment
<
T
>
{
public
FragmentedSegment
(
long
runningIndex
,
ReadOnlyMemory
<
T
>
memory
)
{
...
...
StackExchange.Redis.Tests/Streams.cs
View file @
22c4c1ce
...
...
@@ -121,8 +121,8 @@ public void StreamAddMultipleValuePairsWithManualId()
public
void
StreamConsumerGroupSetId
()
{
var
key
=
GetUniqueKey
(
"group_set_id"
);
var
groupName
=
"test_group"
;
var
consumer
=
"consumer"
;
const
string
groupName
=
"test_group"
;
const
string
consumer
=
"consumer"
;
using
(
var
conn
=
Create
())
{
...
...
@@ -269,7 +269,7 @@ public void StreamConsumerGroupReadFromStreamBeginningWithCount()
// Start reading after id1.
db
.
StreamCreateConsumerGroup
(
key
,
groupName
,
id1
);
var
entries
=
db
.
StreamReadGroup
(
key
,
groupName
,
"test_consumer"
,
StreamPosition
.
NewMessages
,
2
);
// Ensure we only received the requested count and that the IDs match the expected values.
...
...
@@ -430,7 +430,7 @@ public void StreamConsumerGroupReadMultipleOneReadBeginningOneReadNew()
// Ask redis to read from the beginning of both stream, expect messages
// for only the stream set to read from the beginning.
var
groupName
=
"test_group"
;
const
string
groupName
=
"test_group"
;
var
stream1
=
GetUniqueKey
(
"stream1"
);
var
stream2
=
GetUniqueKey
(
"stream2"
);
...
...
@@ -472,7 +472,7 @@ public void StreamConsumerGroupReadMultipleOneReadBeginningOneReadNew()
[
Fact
]
public
void
StreamConsumerGroupReadMultipleOnlyNewMessagesExpectNoResult
()
{
var
groupName
=
"test_group"
;
const
string
groupName
=
"test_group"
;
var
stream1
=
GetUniqueKey
(
"stream1"
);
var
stream2
=
GetUniqueKey
(
"stream2"
);
...
...
@@ -484,7 +484,7 @@ public void StreamConsumerGroupReadMultipleOnlyNewMessagesExpectNoResult()
db
.
StreamAdd
(
stream1
,
"field1-1"
,
"value1-1"
);
db
.
StreamAdd
(
stream2
,
"field2-1"
,
"value2-1"
);
// set both streams to read only new messages (default behavior).
db
.
StreamCreateConsumerGroup
(
stream1
,
groupName
);
db
.
StreamCreateConsumerGroup
(
stream2
,
groupName
);
...
...
@@ -508,7 +508,7 @@ public void StreamConsumerGroupReadMultipleOnlyNewMessagesExpectNoResult()
[
Fact
]
public
void
StreamConsumerGroupReadMultipleOnlyNewMessagesExpect1Result
()
{
var
groupName
=
"test_group"
;
const
string
groupName
=
"test_group"
;
var
stream1
=
GetUniqueKey
(
"stream1"
);
var
stream2
=
GetUniqueKey
(
"stream2"
);
...
...
@@ -551,7 +551,7 @@ public void StreamConsumerGroupReadMultipleOnlyNewMessagesExpect1Result()
[
Fact
]
public
void
StreamConsumerGroupReadMultipleRestrictCount
()
{
var
groupName
=
"test_group"
;
const
string
groupName
=
"test_group"
;
var
stream1
=
GetUniqueKey
(
"stream1"
);
var
stream2
=
GetUniqueKey
(
"stream2"
);
...
...
@@ -767,8 +767,8 @@ public void StreamConsumerGroupViewPendingMessageInfoForConsumer()
public
void
StreamDeleteConsumer
()
{
var
key
=
GetUniqueKey
(
"delete_consumer_group"
);
var
groupName
=
"test_group"
;
var
consumer
=
"test_consumer"
;
const
string
groupName
=
"test_group"
;
const
string
consumer
=
"test_consumer"
;
using
(
var
conn
=
Create
())
{
...
...
@@ -802,8 +802,8 @@ public void StreamDeleteConsumer()
public
void
StreamDeleteConsumerGroup
()
{
var
key
=
GetUniqueKey
(
"delete_consumer_group"
);
var
groupName
=
"test_group"
;
var
consumer
=
"test_consumer"
;
const
string
groupName
=
"test_group"
;
const
string
consumer
=
"test_consumer"
;
using
(
var
conn
=
Create
())
{
...
...
@@ -1056,7 +1056,7 @@ public void StreamPendingNoMessagesOrConsumers()
Assert
.
True
(
pendingInfo
.
Consumers
.
Length
==
0
);
}
}
[
Fact
]
public
void
StreamPositionDefaultValueIsBeginning
()
{
...
...
@@ -1078,8 +1078,8 @@ public void StreamPositionValidateBeginning()
[
Fact
]
public
void
StreamPositionValidateExplicit
()
{
var
explicitValue
=
"1-0"
;
var
position
=
explicitValue
;
const
string
explicitValue
=
"1-0"
;
const
string
position
=
explicitValue
;
Assert
.
Equal
(
explicitValue
,
StreamPosition
.
Resolve
(
position
,
RedisCommand
.
XREAD
));
}
...
...
@@ -1507,7 +1507,7 @@ public void StreamReadRangeReverseWithCount()
var
id1
=
db
.
StreamAdd
(
key
,
"field1"
,
"value1"
);
var
id2
=
db
.
StreamAdd
(
key
,
"fiedl2"
,
"value2"
);
var
entries
=
db
.
StreamRange
(
key
,
id1
,
id2
,
1
,
Order
.
Descending
);
Assert
.
True
(
entries
.
Length
==
1
);
...
...
StackExchange.Redis.Tests/TestBase.cs
View file @
22c4c1ce
...
...
@@ -299,7 +299,6 @@ protected IServer GetAnyMaster(ConnectionMultiplexer muxer)
muxer
.
Resurrecting
+=
(
e
,
t
)
=>
Writer
.
WriteLine
(
$"Resurrecting
{
Format
.
ToString
(
e
)}
as
{
t
}
"
);
muxer
.
Closing
+=
complete
=>
{
int
count
;
lock
(
ActiveMultiplexers
)
{
...
...
@@ -310,7 +309,6 @@ protected IServer GetAnyMaster(ConnectionMultiplexer muxer)
}
}
Writer
.
WriteLine
((
complete
?
"Closed ("
:
"Closing... ("
)
+
count
.
ToString
()
+
" remaining)"
);
};
return
muxer
;
}
...
...
StackExchange.Redis/Profiling/IProfiledCommand.cs
View file @
22c4c1ce
...
...
@@ -33,11 +33,12 @@ public interface IProfiledCommand
CommandFlags
Flags
{
get
;
}
/// <summary>
/// <para>
/// When this command was *created*, will be approximately
/// when the paired method of StackExchange.Redis was called but
/// before that method returned.
///
///
Note that the resolution of the returned DateTime is limited by DateTime.UtcNow.
///
</para>
///
<para>Note that the resolution of the returned DateTime is limited by DateTime.UtcNow.</para>
/// </summary>
DateTime
CommandCreated
{
get
;
}
...
...
@@ -67,17 +68,17 @@ public interface IProfiledCommand
TimeSpan
ResponseToCompletion
{
get
;
}
/// <summary>
/// How long it took this redis command to be processed, from creation to deserializing the final response.
///
/// Note that this TimeSpan *does not* include time spent awaiting a Task in consumer code.
/// <para>How long it took this redis command to be processed, from creation to deserializing the final response.</para>
/// <para>Note that this TimeSpan *does not* include time spent awaiting a Task in consumer code.</para>
/// </summary>
TimeSpan
ElapsedTime
{
get
;
}
/// <summary>
/// <para>
/// If a command has to be resent due to an ASK or MOVED response from redis (in a cluster configuration),
/// the second sending of the command will have this property set to the original IProfiledCommand.
///
///
This can only be set if redis is configured as a cluster.
///
</para>
///
<para>This can only be set if redis is configured as a cluster.</para>
/// </summary>
IProfiledCommand
RetransmissionOf
{
get
;
}
...
...
TestConsole/Program.cs
View file @
22c4c1ce
...
...
@@ -23,7 +23,7 @@ private static void Main()
RunCompetingBatchesOnSameMuxer
();
}
while
(
DateTime
.
UtcNow
<
stop
);
}
static
ConnectionMultiplexer
Create
()
private
static
ConnectionMultiplexer
Create
()
{
var
options
=
new
ConfigurationOptions
{
...
...
@@ -42,10 +42,14 @@ public static void RunCompetingBatchesOnSameMuxer()
{
var
db
=
muxer
.
GetDatabase
();
Thread
x
=
new
Thread
(
state
=>
BatchRunPings
((
IDatabase
)
state
));
x
.
Name
=
nameof
(
BatchRunPings
);
Thread
y
=
new
Thread
(
state
=>
BatchRunIntegers
((
IDatabase
)
state
));
y
.
Name
=
nameof
(
BatchRunIntegers
);
Thread
x
=
new
Thread
(
state
=>
BatchRunPings
((
IDatabase
)
state
))
{
Name
=
nameof
(
BatchRunPings
)
};
Thread
y
=
new
Thread
(
state
=>
BatchRunIntegers
((
IDatabase
)
state
))
{
Name
=
nameof
(
BatchRunIntegers
)
};
var
watch
=
Stopwatch
.
StartNew
();
x
.
Start
(
db
);
...
...
@@ -59,7 +63,7 @@ public static void RunCompetingBatchesOnSameMuxer()
}
}
static
RedisKey
Me
([
CallerMemberName
]
string
caller
=
null
)
=>
caller
;
private
static
RedisKey
Me
([
CallerMemberName
]
string
caller
=
null
)
=>
caller
;
private
static
void
BatchRunIntegers
(
IDatabase
db
)
{
...
...
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