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
53127b87
Commit
53127b87
authored
Jul 03, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SetPop/SetPopAsync count overloads
This API was missing - resolves #203
parent
de15da12
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
101 additions
and
1 deletion
+101
-1
DatabaseWrapperTests.cs
StackExchange.Redis.Tests/DatabaseWrapperTests.cs
+3
-0
Sets.cs
StackExchange.Redis.Tests/Sets.cs
+52
-0
WrapperBaseTests.cs
StackExchange.Redis.Tests/WrapperBaseTests.cs
+3
-0
IDatabase.cs
...xchange.Redis/StackExchange/Redis/Interfaces/IDatabase.cs
+11
-1
IDatabaseAsync.cs
...ge.Redis/StackExchange/Redis/Interfaces/IDatabaseAsync.cs
+10
-0
DatabaseWrapper.cs
.../StackExchange/Redis/KeyspaceIsolation/DatabaseWrapper.cs
+5
-0
WrapperBase.cs
...edis/StackExchange/Redis/KeyspaceIsolation/WrapperBase.cs
+5
-0
RedisDatabase.cs
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
+12
-0
No files found.
StackExchange.Redis.Tests/DatabaseWrapperTests.cs
View file @
53127b87
...
...
@@ -567,6 +567,9 @@ public void SetPop()
{
wrapper
.
SetPop
(
"key"
,
CommandFlags
.
HighPriority
);
mock
.
Verify
(
_
=>
_
.
SetPop
(
"prefix:key"
,
CommandFlags
.
HighPriority
));
wrapper
.
SetPop
(
"key"
,
5
,
CommandFlags
.
HighPriority
);
mock
.
Verify
(
_
=>
_
.
SetPop
(
"prefix:key"
,
5
,
CommandFlags
.
HighPriority
));
}
[
Fact
]
...
...
StackExchange.Redis.Tests/Sets.cs
View file @
53127b87
...
...
@@ -55,5 +55,57 @@ public async Task SetRemoveArgTests()
Assert
.
Equal
(
0
,
await
db
.
SetRemoveAsync
(
key
,
values
,
CommandFlags
.
HighPriority
).
ForAwait
());
}
}
[
Fact
]
public
void
SetPop
()
{
using
(
var
conn
=
Create
())
{
var
db
=
conn
.
GetDatabase
();
var
key
=
Me
();
for
(
int
i
=
1
;
i
<
11
;
i
++)
{
db
.
SetAdd
(
key
,
i
);
}
var
random
=
db
.
SetPop
(
key
);
Assert
.
False
(
random
.
IsNull
);
Assert
.
True
((
int
)
random
>
0
);
Assert
.
True
((
int
)
random
<
10
);
Assert
.
Equal
(
9
,
db
.
SetLength
(
key
));
var
moreRandoms
=
db
.
SetPop
(
key
,
2
);
Assert
.
Equal
(
2
,
moreRandoms
.
Length
);
Assert
.
False
(
moreRandoms
[
0
].
IsNull
);
Assert
.
Equal
(
7
,
db
.
SetLength
(
key
));
}
}
[
Fact
]
public
async
Task
SetPopAsync
()
{
using
(
var
conn
=
Create
())
{
var
db
=
conn
.
GetDatabase
();
var
key
=
Me
();
for
(
int
i
=
1
;
i
<
11
;
i
++)
{
db
.
SetAdd
(
key
,
i
);
}
var
random
=
await
db
.
SetPopAsync
(
key
).
ForAwait
();
Assert
.
False
(
random
.
IsNull
);
Assert
.
True
((
int
)
random
>
0
);
Assert
.
True
((
int
)
random
<
10
);
Assert
.
Equal
(
9
,
db
.
SetLength
(
key
));
var
moreRandoms
=
await
db
.
SetPopAsync
(
key
,
2
).
ForAwait
();
Assert
.
Equal
(
2
,
moreRandoms
.
Length
);
Assert
.
False
(
moreRandoms
[
0
].
IsNull
);
Assert
.
Equal
(
7
,
db
.
SetLength
(
key
));
}
}
}
}
StackExchange.Redis.Tests/WrapperBaseTests.cs
View file @
53127b87
...
...
@@ -539,6 +539,9 @@ public void SetPopAsync()
{
wrapper
.
SetPopAsync
(
"key"
,
CommandFlags
.
HighPriority
);
mock
.
Verify
(
_
=>
_
.
SetPopAsync
(
"prefix:key"
,
CommandFlags
.
HighPriority
));
wrapper
.
SetPopAsync
(
"key"
,
5
,
CommandFlags
.
HighPriority
);
mock
.
Verify
(
_
=>
_
.
SetPopAsync
(
"prefix:key"
,
5
,
CommandFlags
.
HighPriority
));
}
[
Fact
]
...
...
StackExchange.Redis/StackExchange/Redis/Interfaces/IDatabase.cs
View file @
53127b87
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Net
;
...
...
@@ -962,6 +962,16 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <remarks>https://redis.io/commands/spop</remarks>
RedisValue
SetPop
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Removes and returns the specified number of random elements from the set value stored at key.
/// </summary>
/// <param name="key">The key of the set.</param>
/// <param name="count">The number of elements to return.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The removed elements, or nil when key does not exist.</returns>
/// <remarks>https://redis.io/commands/spop</remarks>
RedisValue
[]
SetPop
(
RedisKey
key
,
long
count
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Return a random element from the set value stored at key.
/// </summary>
...
...
StackExchange.Redis/StackExchange/Redis/Interfaces/IDatabaseAsync.cs
View file @
53127b87
...
...
@@ -925,6 +925,16 @@ public interface IDatabaseAsync : IRedisAsync
/// <remarks>https://redis.io/commands/spop</remarks>
Task
<
RedisValue
>
SetPopAsync
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Removes and returns the specified number of random elements from the set value stored at key.
/// </summary>
/// <param name="key">The key of the set.</param>
/// <param name="count">The number of elements to return.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The removed elements, or nil when key does not exist.</returns>
/// <remarks>https://redis.io/commands/spop</remarks>
Task
<
RedisValue
[
]>
SetPopAsync
(
RedisKey
key
,
long
count
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Return a random element from the set value stored at key.
/// </summary>
...
...
StackExchange.Redis/StackExchange/Redis/KeyspaceIsolation/DatabaseWrapper.cs
View file @
53127b87
...
...
@@ -447,6 +447,11 @@ public RedisValue SetPop(RedisKey key, CommandFlags flags = CommandFlags.None)
return
Inner
.
SetPop
(
ToInner
(
key
),
flags
);
}
public
RedisValue
[]
SetPop
(
RedisKey
key
,
long
count
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
return
Inner
.
SetPop
(
ToInner
(
key
),
count
,
flags
);
}
public
RedisValue
SetRandomMember
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
return
Inner
.
SetRandomMember
(
ToInner
(
key
),
flags
);
...
...
StackExchange.Redis/StackExchange/Redis/KeyspaceIsolation/WrapperBase.cs
View file @
53127b87
...
...
@@ -426,6 +426,11 @@ public Task<RedisValue> SetPopAsync(RedisKey key, CommandFlags flags = CommandFl
return
Inner
.
SetPopAsync
(
ToInner
(
key
),
flags
);
}
public
Task
<
RedisValue
[
]>
SetPopAsync
(
RedisKey
key
,
long
count
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
return
Inner
.
SetPopAsync
(
ToInner
(
key
),
count
,
flags
);
}
public
Task
<
RedisValue
>
SetRandomMemberAsync
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
return
Inner
.
SetRandomMemberAsync
(
ToInner
(
key
),
flags
);
...
...
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
View file @
53127b87
...
...
@@ -1251,6 +1251,18 @@ public Task<RedisValue> SetPopAsync(RedisKey key, CommandFlags flags = CommandFl
return
ExecuteAsync
(
msg
,
ResultProcessor
.
RedisValue
);
}
public
RedisValue
[]
SetPop
(
RedisKey
key
,
long
count
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(
Database
,
flags
,
RedisCommand
.
SPOP
,
key
,
count
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
RedisValueArray
);
}
public
Task
<
RedisValue
[
]>
SetPopAsync
(
RedisKey
key
,
long
count
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(
Database
,
flags
,
RedisCommand
.
SPOP
,
key
,
count
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
RedisValueArray
);
}
public
RedisValue
SetRandomMember
(
RedisKey
key
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(
Database
,
flags
,
RedisCommand
.
SRANDMEMBER
,
key
);
...
...
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