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
bb0d231a
Commit
bb0d231a
authored
Nov 20, 2019
by
Aart Jan Kaptijn
Committed by
Marc Gravell
Nov 20, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix for #1282: do no-op when adding 0 values to a set (#1283)
parent
f6d050e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
RedisDatabase.cs
src/StackExchange.Redis/RedisDatabase.cs
+2
-0
Sets.cs
tests/StackExchange.Redis.Tests/Sets.cs
+36
-0
No files found.
src/StackExchange.Redis/RedisDatabase.cs
View file @
bb0d231a
...
@@ -1216,6 +1216,7 @@ public bool SetAdd(RedisKey key, RedisValue value, CommandFlags flags = CommandF
...
@@ -1216,6 +1216,7 @@ public bool SetAdd(RedisKey key, RedisValue value, CommandFlags flags = CommandF
public
long
SetAdd
(
RedisKey
key
,
RedisValue
[]
values
,
CommandFlags
flags
=
CommandFlags
.
None
)
public
long
SetAdd
(
RedisKey
key
,
RedisValue
[]
values
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
{
if
(
values
.
Length
==
0
)
return
0
;
var
msg
=
Message
.
Create
(
Database
,
flags
,
RedisCommand
.
SADD
,
key
,
values
);
var
msg
=
Message
.
Create
(
Database
,
flags
,
RedisCommand
.
SADD
,
key
,
values
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
Int64
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
Int64
);
}
}
...
@@ -1228,6 +1229,7 @@ public Task<bool> SetAddAsync(RedisKey key, RedisValue value, CommandFlags flags
...
@@ -1228,6 +1229,7 @@ public Task<bool> SetAddAsync(RedisKey key, RedisValue value, CommandFlags flags
public
Task
<
long
>
SetAddAsync
(
RedisKey
key
,
RedisValue
[]
values
,
CommandFlags
flags
=
CommandFlags
.
None
)
public
Task
<
long
>
SetAddAsync
(
RedisKey
key
,
RedisValue
[]
values
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
{
if
(
values
.
Length
==
0
)
return
Task
.
FromResult
<
long
>(
0
);
var
msg
=
Message
.
Create
(
Database
,
flags
,
RedisCommand
.
SADD
,
key
,
values
);
var
msg
=
Message
.
Create
(
Database
,
flags
,
RedisCommand
.
SADD
,
key
,
values
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
Int64
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
Int64
);
}
}
...
...
tests/StackExchange.Redis.Tests/Sets.cs
View file @
bb0d231a
...
@@ -189,5 +189,41 @@ public async Task SetPopMulti_Zero_Async()
...
@@ -189,5 +189,41 @@ public async Task SetPopMulti_Zero_Async()
Assert
.
Equal
(
10
,
db
.
SetLength
(
key
));
Assert
.
Equal
(
10
,
db
.
SetLength
(
key
));
}
}
}
}
[
Fact
]
public
void
SetAdd_Zero
()
{
using
(
var
conn
=
Create
())
{
var
db
=
conn
.
GetDatabase
();
var
key
=
Me
();
db
.
KeyDelete
(
key
,
CommandFlags
.
FireAndForget
);
var
result
=
db
.
SetAdd
(
key
,
new
RedisValue
[
0
]);
Assert
.
Equal
(
0
,
result
);
Assert
.
Equal
(
0
,
db
.
SetLength
(
key
));
}
}
[
Fact
]
public
async
Task
SetAdd_Zero_Async
()
{
using
(
var
conn
=
Create
())
{
var
db
=
conn
.
GetDatabase
();
var
key
=
Me
();
db
.
KeyDelete
(
key
,
CommandFlags
.
FireAndForget
);
var
t
=
db
.
SetAddAsync
(
key
,
new
RedisValue
[
0
]);
Assert
.
True
(
t
.
IsCompleted
);
// sync
var
count
=
await
t
;
Assert
.
Equal
(
0
,
count
);
Assert
.
Equal
(
0
,
db
.
SetLength
(
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