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
bc9e4fe2
Commit
bc9e4fe2
authored
Apr 04, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ZREMRANGEBYSCORE; Fix NUMSUB; Duplicate PUBLISH on database API
parent
33704f3f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
62 deletions
+93
-62
IDatabase.cs
StackExchange.Redis/StackExchange/Redis/IDatabase.cs
+7
-0
IDatabaseAsync.cs
StackExchange.Redis/StackExchange/Redis/IDatabaseAsync.cs
+8
-0
RedisDatabase.cs
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
+76
-60
RedisServer.cs
StackExchange.Redis/StackExchange/Redis/RedisServer.cs
+2
-2
No files found.
StackExchange.Redis/StackExchange/Redis/IDatabase.cs
View file @
bc9e4fe2
...
...
@@ -423,6 +423,13 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// Takes a lock (specifying a token value) if it is not already taken
/// </summary>
bool
LockTake
(
RedisKey
key
,
RedisValue
value
,
TimeSpan
expiry
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Posts a message to the given channel.
/// </summary>
/// <returns>the number of clients that received the message.</returns>
/// <remarks>http://redis.io/commands/publish</remarks>
long
Publish
(
RedisChannel
channel
,
RedisValue
message
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Execute a Lua script against the server
/// </summary>
...
...
StackExchange.Redis/StackExchange/Redis/IDatabaseAsync.cs
View file @
bc9e4fe2
...
...
@@ -171,6 +171,7 @@ public interface IDatabaseAsync : IRedisAsync
/// </summary>
[
IgnoreNamePrefix
(
true
)]
bool
IsConnected
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Removes the specified key. A key is ignored if it does not exist.
/// </summary>
...
...
@@ -402,6 +403,13 @@ public interface IDatabaseAsync : IRedisAsync
/// Takes a lock (specifying a token value) if it is not already taken
/// </summary>
Task
<
bool
>
LockTakeAsync
(
RedisKey
key
,
RedisValue
value
,
TimeSpan
expiry
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Posts a message to the given channel.
/// </summary>
/// <returns>the number of clients that received the message.</returns>
/// <remarks>http://redis.io/commands/publish</remarks>
Task
<
long
>
PublishAsync
(
RedisChannel
channel
,
RedisValue
message
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Execute a Lua script against the server
/// </summary>
...
...
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
View file @
bc9e4fe2
...
...
@@ -251,6 +251,66 @@ public Task<RedisValue[]> HashValuesAsync(RedisKey key, CommandFlags flags = Com
return
ExecuteAsync
(
msg
,
ResultProcessor
.
RedisValueArray
);
}
public
bool
HyperLogLogAdd
(
RedisKey
key
,
RedisValue
value
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFADD
,
key
,
value
);
return
ExecuteSync
(
cmd
,
ResultProcessor
.
Boolean
);
}
public
bool
HyperLogLogAdd
(
RedisKey
key
,
RedisValue
[]
values
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFADD
,
key
,
values
);
return
ExecuteSync
(
cmd
,
ResultProcessor
.
Boolean
);
}
public
Task
<
bool
>
HyperLogLogAddAsync
(
RedisKey
key
,
RedisValue
value
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFADD
,
key
,
value
);
return
ExecuteAsync
(
cmd
,
ResultProcessor
.
Boolean
);
}
public
Task
<
bool
>
HyperLogLogAddAsync
(
RedisKey
key
,
RedisValue
[]
values
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFADD
,
key
,
values
);
return
ExecuteAsync
(
cmd
,
ResultProcessor
.
Boolean
);
}
public
long
HyperLogLogLength
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFCOUNT
,
key
);
return
ExecuteSync
(
cmd
,
ResultProcessor
.
Int64
);
}
public
Task
<
long
>
HyperLogLogLengthAsync
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFCOUNT
,
key
);
return
ExecuteAsync
(
cmd
,
ResultProcessor
.
Int64
);
}
public
void
HyperLogLogMerge
(
RedisKey
destination
,
RedisKey
first
,
RedisKey
second
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFMERGE
,
destination
,
first
,
second
);
ExecuteSync
(
cmd
,
ResultProcessor
.
DemandOK
);
}
public
void
HyperLogLogMerge
(
RedisKey
destination
,
RedisKey
[]
sourceKeys
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFMERGE
,
destination
,
sourceKeys
);
ExecuteSync
(
cmd
,
ResultProcessor
.
DemandOK
);
}
public
Task
HyperLogLogMergeAsync
(
RedisKey
destination
,
RedisKey
first
,
RedisKey
second
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFMERGE
,
destination
,
first
,
second
);
return
ExecuteAsync
(
cmd
,
ResultProcessor
.
DemandOK
);
}
public
Task
HyperLogLogMergeAsync
(
RedisKey
destination
,
RedisKey
[]
sourceKeys
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFMERGE
,
destination
,
sourceKeys
);
return
ExecuteAsync
(
cmd
,
ResultProcessor
.
DemandOK
);
}
public
EndPoint
IdentifyEndpoint
(
RedisKey
key
=
default
(
RedisKey
),
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
key
.
IsNull
?
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PING
)
:
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
EXISTS
,
key
);
...
...
@@ -268,6 +328,7 @@ public bool IsConnected(RedisKey key, CommandFlags flags = CommandFlags.None)
var
server
=
multiplexer
.
SelectServer
(
Db
,
RedisCommand
.
PING
,
flags
,
key
);
return
server
!=
null
&&
server
.
IsConnected
;
}
public
bool
KeyDelete
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
DEL
,
key
);
...
...
@@ -681,6 +742,20 @@ public Task<bool> LockTakeAsync(RedisKey key, RedisValue value, TimeSpan expiry,
{
return
StringSetAsync
(
key
,
value
,
expiry
,
When
.
NotExists
,
flags
);
}
public
long
Publish
(
RedisChannel
channel
,
RedisValue
message
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
if
(
channel
.
IsNullOrEmpty
)
throw
new
ArgumentNullException
(
"channel"
);
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
PUBLISH
,
channel
,
message
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
Int64
);
}
public
Task
<
long
>
PublishAsync
(
RedisChannel
channel
,
RedisValue
message
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
if
(
channel
.
IsNullOrEmpty
)
throw
new
ArgumentNullException
(
"channel"
);
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
PUBLISH
,
channel
,
message
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
Int64
);
}
public
RedisResult
ScriptEvaluate
(
string
script
,
RedisKey
[]
keys
=
null
,
RedisValue
[]
values
=
null
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
new
ScriptEvalMessage
(
Db
,
flags
,
RedisCommand
.
EVAL
,
script
,
keys
??
RedisKey
.
EmptyArray
,
values
??
RedisValue
.
EmptyArray
);
...
...
@@ -1655,7 +1730,7 @@ private Message GetSortedSetRangeByScoreMessage(RedisKey key, double start, doub
private
Message
GetSortedSetRemoveRangeByScoreMessage
(
RedisKey
key
,
double
start
,
double
stop
,
Exclude
exclude
,
CommandFlags
flags
)
{
return
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
ZREMRANGEBYSCORE
,
key
,
GetRange
(
start
,
exclude
,
true
),
GetRange
(
st
art
,
exclude
,
false
));
GetRange
(
start
,
exclude
,
true
),
GetRange
(
st
op
,
exclude
,
false
));
}
private
Message
GetStringBitOperationMessage
(
Bitwise
operation
,
RedisKey
destination
,
RedisKey
[]
keys
,
CommandFlags
flags
)
...
...
@@ -1810,65 +1885,6 @@ private IEnumerable<T> TryScan<T>(RedisKey key, RedisValue pattern, int pageSize
if
(
ScanUtils
.
IsNil
(
pattern
))
pattern
=
(
byte
[])
null
;
return
new
ScanIterator
<
T
>(
this
,
server
,
key
,
pattern
,
pageSize
,
flags
,
command
,
processor
).
Read
();
}
public
bool
HyperLogLogAdd
(
RedisKey
key
,
RedisValue
value
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFADD
,
key
,
value
);
return
ExecuteSync
(
cmd
,
ResultProcessor
.
Boolean
);
}
public
bool
HyperLogLogAdd
(
RedisKey
key
,
RedisValue
[]
values
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFADD
,
key
,
values
);
return
ExecuteSync
(
cmd
,
ResultProcessor
.
Boolean
);
}
public
long
HyperLogLogLength
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFCOUNT
,
key
);
return
ExecuteSync
(
cmd
,
ResultProcessor
.
Int64
);
}
public
void
HyperLogLogMerge
(
RedisKey
destination
,
RedisKey
first
,
RedisKey
second
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFMERGE
,
destination
,
first
,
second
);
ExecuteSync
(
cmd
,
ResultProcessor
.
DemandOK
);
}
public
void
HyperLogLogMerge
(
RedisKey
destination
,
RedisKey
[]
sourceKeys
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFMERGE
,
destination
,
sourceKeys
);
ExecuteSync
(
cmd
,
ResultProcessor
.
DemandOK
);
}
public
Task
<
bool
>
HyperLogLogAddAsync
(
RedisKey
key
,
RedisValue
value
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFADD
,
key
,
value
);
return
ExecuteAsync
(
cmd
,
ResultProcessor
.
Boolean
);
}
public
Task
<
bool
>
HyperLogLogAddAsync
(
RedisKey
key
,
RedisValue
[]
values
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFADD
,
key
,
values
);
return
ExecuteAsync
(
cmd
,
ResultProcessor
.
Boolean
);
}
public
Task
<
long
>
HyperLogLogLengthAsync
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFCOUNT
,
key
);
return
ExecuteAsync
(
cmd
,
ResultProcessor
.
Int64
);
}
public
Task
HyperLogLogMergeAsync
(
RedisKey
destination
,
RedisKey
first
,
RedisKey
second
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFMERGE
,
destination
,
first
,
second
);
return
ExecuteAsync
(
cmd
,
ResultProcessor
.
DemandOK
);
}
public
Task
HyperLogLogMergeAsync
(
RedisKey
destination
,
RedisKey
[]
sourceKeys
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
cmd
=
Message
.
Create
(
Db
,
flags
,
RedisCommand
.
PFMERGE
,
destination
,
sourceKeys
);
return
ExecuteAsync
(
cmd
,
ResultProcessor
.
DemandOK
);
}
internal
static
class
ScanUtils
{
public
const
int
DefaultPageSize
=
10
;
...
...
StackExchange.Redis/StackExchange/Redis/RedisServer.cs
View file @
bc9e4fe2
...
...
@@ -402,13 +402,13 @@ public Task<RedisChannel[]> SubscriptionChannelsAsync(RedisChannel pattern = def
public
long
SubscriptionPatternCount
(
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
PUB
LISH
,
RedisLiterals
.
NUMPAT
);
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
PUB
SUB
,
RedisLiterals
.
NUMPAT
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
Int64
);
}
public
Task
<
long
>
SubscriptionPatternCountAsync
(
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
PUB
LISH
,
RedisLiterals
.
NUMPAT
);
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
PUB
SUB
,
RedisLiterals
.
NUMPAT
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
Int64
);
}
...
...
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