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
9ebe3e46
Commit
9ebe3e46
authored
Sep 11, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixup PUBSUB command (NUMSUB and CHANNELS)
parent
0190e1a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
5 deletions
+65
-5
PubSubCommand.cs
StackExchange.Redis.Tests/PubSubCommand.cs
+41
-0
StackExchange.Redis.Tests.csproj
StackExchange.Redis.Tests/StackExchange.Redis.Tests.csproj
+1
-0
RedisServer.cs
StackExchange.Redis/StackExchange/Redis/RedisServer.cs
+2
-2
ResultProcessor.cs
StackExchange.Redis/StackExchange/Redis/ResultProcessor.cs
+21
-3
No files found.
StackExchange.Redis.Tests/PubSubCommand.cs
0 → 100644
View file @
9ebe3e46
using
NUnit.Framework
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.IO
;
namespace
StackExchange.Redis.Tests
{
[
TestFixture
]
public
class
PubSubCommand
:
TestBase
{
[
Test
]
public
void
SubscriberCount
()
{
using
(
var
conn
=
Create
())
{
RedisChannel
channel
=
Me
()
+
Guid
.
NewGuid
();
var
server
=
conn
.
GetServer
(
conn
.
GetEndPoints
()[
0
]);
var
channels
=
server
.
SubscriptionChannels
(
Me
()
+
"*"
);
Assert
.
IsFalse
(
channels
.
Contains
(
channel
));
long
justWork
=
server
.
SubscriptionPatternCount
();
var
count
=
server
.
SubscriptionSubscriberCount
(
channel
);
Assert
.
AreEqual
(
0
,
count
);
conn
.
GetSubscriber
().
Subscribe
(
channel
,
delegate
{
});
count
=
server
.
SubscriptionSubscriberCount
(
channel
);
Assert
.
AreEqual
(
1
,
count
);
channels
=
server
.
SubscriptionChannels
(
Me
()
+
"*"
);
Assert
.
IsTrue
(
channels
.
Contains
(
channel
));
}
}
protected
override
string
GetConfiguration
()
{
return
"ubuntu"
;
}
}
}
StackExchange.Redis.Tests/StackExchange.Redis.Tests.csproj
View file @
9ebe3e46
...
...
@@ -92,6 +92,7 @@
<Compile
Include=
"PreserveOrder.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"PubSub.cs"
/>
<Compile
Include=
"PubSubCommand.cs"
/>
<Compile
Include=
"RealWorld.cs"
/>
<Compile
Include=
"Scans.cs"
/>
<Compile
Include=
"Scripting.cs"
/>
...
...
StackExchange.Redis/StackExchange/Redis/RedisServer.cs
View file @
9ebe3e46
...
...
@@ -467,13 +467,13 @@ public Task<long> SubscriptionPatternCountAsync(CommandFlags flags = CommandFlag
public
long
SubscriptionSubscriberCount
(
RedisChannel
channel
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
PUBSUB
,
RedisLiterals
.
NUMSUB
,
channel
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
Int64
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
PubSubNumSub
);
}
public
Task
<
long
>
SubscriptionSubscriberCountAsync
(
RedisChannel
channel
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
PUBSUB
,
RedisLiterals
.
NUMSUB
,
channel
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
Int64
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
PubSubNumSub
);
}
public
DateTime
Time
(
CommandFlags
flags
=
CommandFlags
.
None
)
...
...
StackExchange.Redis/StackExchange/Redis/ResultProcessor.cs
View file @
9ebe3e46
...
...
@@ -41,7 +41,8 @@ abstract class ResultProcessor
Info
=
new
InfoProcessor
();
public
static
readonly
ResultProcessor
<
long
>
Int64
=
new
Int64Processor
();
Int64
=
new
Int64Processor
(),
PubSubNumSub
=
new
PubSubNumSubProcessor
();
public
static
readonly
ResultProcessor
<
double
?>
NullableDouble
=
new
NullableDoubleProcessor
();
...
...
@@ -879,7 +880,7 @@ static string Normalize(string category)
}
}
sealed
class
Int64Processor
:
ResultProcessor
<
long
>
class
Int64Processor
:
ResultProcessor
<
long
>
{
protected
override
bool
SetResultCore
(
PhysicalConnection
connection
,
Message
message
,
RawResult
result
)
{
...
...
@@ -899,6 +900,23 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
return
false
;
}
}
class
PubSubNumSubProcessor
:
Int64Processor
{
protected
override
bool
SetResultCore
(
PhysicalConnection
connection
,
Message
message
,
RawResult
result
)
{
if
(
result
.
Type
==
ResultType
.
MultiBulk
)
{
var
arr
=
result
.
GetItems
();
long
val
;
if
(
arr
!=
null
&&
arr
.
Length
==
2
&&
arr
[
1
].
TryGetInt64
(
out
val
))
{
SetResult
(
message
,
val
);
return
true
;
}
}
return
base
.
SetResultCore
(
connection
,
message
,
result
);
}
}
sealed
class
NullableDoubleProcessor
:
ResultProcessor
<
double
?>
{
...
...
@@ -970,7 +988,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
byte
[]
channelPrefix
=
connection
.
ChannelPrefix
;
for
(
int
i
=
0
;
i
<
final
.
Length
;
i
++)
{
final
[
i
]
=
result
.
AsRedisChannel
(
channelPrefix
);
final
[
i
]
=
arr
[
i
]
.
AsRedisChannel
(
channelPrefix
);
}
}
SetResult
(
message
,
final
);
...
...
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