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
b0a07a76
Commit
b0a07a76
authored
Oct 19, 2019
by
Eitan Har-Shoshanim
Committed by
Nick Craver
Oct 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add HSTRLEN command implementation and testing (#1241)
Implements #1238 - adds `HSTRLEN` command and testing.
parent
cf238f30
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
96 additions
and
1 deletion
+96
-1
RedisCommand.cs
src/StackExchange.Redis/Enums/RedisCommand.cs
+1
-0
IDatabase.cs
src/StackExchange.Redis/Interfaces/IDatabase.cs
+10
-0
IDatabaseAsync.cs
src/StackExchange.Redis/Interfaces/IDatabaseAsync.cs
+10
-0
DatabaseWrapper.cs
src/StackExchange.Redis/KeyspaceIsolation/DatabaseWrapper.cs
+5
-0
WrapperBase.cs
src/StackExchange.Redis/KeyspaceIsolation/WrapperBase.cs
+5
-0
RedisDatabase.cs
src/StackExchange.Redis/RedisDatabase.cs
+13
-0
RedisFeatures.cs
src/StackExchange.Redis/RedisFeatures.cs
+5
-0
DatabaseWrapperTests.cs
tests/StackExchange.Redis.Tests/DatabaseWrapperTests.cs
+7
-0
Strings.cs
tests/StackExchange.Redis.Tests/Strings.cs
+32
-0
WrapperBaseTests.cs
tests/StackExchange.Redis.Tests/WrapperBaseTests.cs
+8
-1
No files found.
src/StackExchange.Redis/Enums/RedisCommand.cs
View file @
b0a07a76
...
@@ -65,6 +65,7 @@ internal enum RedisCommand
...
@@ -65,6 +65,7 @@ internal enum RedisCommand
HSCAN
,
HSCAN
,
HSET
,
HSET
,
HSETNX
,
HSETNX
,
HSTRLEN
,
HVALS
,
HVALS
,
INCR
,
INCR
,
...
...
src/StackExchange.Redis/Interfaces/IDatabase.cs
View file @
b0a07a76
...
@@ -358,6 +358,16 @@ public interface IDatabase : IRedis, IDatabaseAsync
...
@@ -358,6 +358,16 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <remarks>https://redis.io/commands/hsetnx</remarks>
/// <remarks>https://redis.io/commands/hsetnx</remarks>
bool
HashSet
(
RedisKey
key
,
RedisValue
hashField
,
RedisValue
value
,
When
when
=
When
.
Always
,
CommandFlags
flags
=
CommandFlags
.
None
);
bool
HashSet
(
RedisKey
key
,
RedisValue
hashField
,
RedisValue
value
,
When
when
=
When
.
Always
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Returns the string length of the value associated with field in the hash stored at key.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashField">The field containing the string</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>the length of the string at field, or 0 when key does not exist.</returns>
/// <remarks>https://redis.io/commands/hstrlen</remarks>
long
HashStringLength
(
RedisKey
key
,
RedisValue
hashField
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// <summary>
/// Returns all values in the hash stored at key.
/// Returns all values in the hash stored at key.
/// </summary>
/// </summary>
...
...
src/StackExchange.Redis/Interfaces/IDatabaseAsync.cs
View file @
b0a07a76
...
@@ -322,6 +322,16 @@ public interface IDatabaseAsync : IRedisAsync
...
@@ -322,6 +322,16 @@ public interface IDatabaseAsync : IRedisAsync
/// <remarks>https://redis.io/commands/hsetnx</remarks>
/// <remarks>https://redis.io/commands/hsetnx</remarks>
Task
<
bool
>
HashSetAsync
(
RedisKey
key
,
RedisValue
hashField
,
RedisValue
value
,
When
when
=
When
.
Always
,
CommandFlags
flags
=
CommandFlags
.
None
);
Task
<
bool
>
HashSetAsync
(
RedisKey
key
,
RedisValue
hashField
,
RedisValue
value
,
When
when
=
When
.
Always
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// Returns the string length of the value associated with field in the hash stored at key.
/// </summary>
/// <param name="key">The key of the hash.</param>
/// <param name="hashField">The field containing the string</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>the length of the string at field, or 0 when key does not exist.</returns>
/// <remarks>https://redis.io/commands/hstrlen</remarks>
Task
<
long
>
HashStringLengthAsync
(
RedisKey
key
,
RedisValue
hashField
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
/// <summary>
/// Returns all values in the hash stored at key.
/// Returns all values in the hash stored at key.
/// </summary>
/// </summary>
...
...
src/StackExchange.Redis/KeyspaceIsolation/DatabaseWrapper.cs
View file @
b0a07a76
...
@@ -152,6 +152,11 @@ public bool HashSet(RedisKey key, RedisValue hashField, RedisValue value, When w
...
@@ -152,6 +152,11 @@ public bool HashSet(RedisKey key, RedisValue hashField, RedisValue value, When w
return
Inner
.
HashSet
(
ToInner
(
key
),
hashField
,
value
,
when
,
flags
);
return
Inner
.
HashSet
(
ToInner
(
key
),
hashField
,
value
,
when
,
flags
);
}
}
public
long
HashStringLength
(
RedisKey
key
,
RedisValue
hashField
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
return
Inner
.
HashStringLength
(
ToInner
(
key
),
hashField
,
flags
);
}
public
void
HashSet
(
RedisKey
key
,
HashEntry
[]
hashFields
,
CommandFlags
flags
=
CommandFlags
.
None
)
public
void
HashSet
(
RedisKey
key
,
HashEntry
[]
hashFields
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
{
Inner
.
HashSet
(
ToInner
(
key
),
hashFields
,
flags
);
Inner
.
HashSet
(
ToInner
(
key
),
hashFields
,
flags
);
...
...
src/StackExchange.Redis/KeyspaceIsolation/WrapperBase.cs
View file @
b0a07a76
...
@@ -128,6 +128,11 @@ public Task<bool> HashSetAsync(RedisKey key, RedisValue hashField, RedisValue va
...
@@ -128,6 +128,11 @@ public Task<bool> HashSetAsync(RedisKey key, RedisValue hashField, RedisValue va
return
Inner
.
HashSetAsync
(
ToInner
(
key
),
hashField
,
value
,
when
,
flags
);
return
Inner
.
HashSetAsync
(
ToInner
(
key
),
hashField
,
value
,
when
,
flags
);
}
}
public
Task
<
long
>
HashStringLengthAsync
(
RedisKey
key
,
RedisValue
hashField
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
return
Inner
.
HashStringLengthAsync
(
ToInner
(
key
),
hashField
,
flags
);
}
public
Task
HashSetAsync
(
RedisKey
key
,
HashEntry
[]
hashFields
,
CommandFlags
flags
=
CommandFlags
.
None
)
public
Task
HashSetAsync
(
RedisKey
key
,
HashEntry
[]
hashFields
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
{
return
Inner
.
HashSetAsync
(
ToInner
(
key
),
hashFields
,
flags
);
return
Inner
.
HashSetAsync
(
ToInner
(
key
),
hashFields
,
flags
);
...
...
src/StackExchange.Redis/RedisDatabase.cs
View file @
b0a07a76
...
@@ -438,6 +438,13 @@ public void HashSet(RedisKey key, HashEntry[] hashFields, CommandFlags flags = C
...
@@ -438,6 +438,13 @@ public void HashSet(RedisKey key, HashEntry[] hashFields, CommandFlags flags = C
ExecuteSync
(
msg
,
ResultProcessor
.
DemandOK
);
ExecuteSync
(
msg
,
ResultProcessor
.
DemandOK
);
}
}
public
long
HashStringLength
(
RedisKey
key
,
RedisValue
hashField
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(
Database
,
flags
,
RedisCommand
.
HSTRLEN
,
key
,
hashField
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
Int64
);
}
public
Task
<
bool
>
HashSetAsync
(
RedisKey
key
,
RedisValue
hashField
,
RedisValue
value
,
When
when
=
When
.
Always
,
CommandFlags
flags
=
CommandFlags
.
None
)
public
Task
<
bool
>
HashSetAsync
(
RedisKey
key
,
RedisValue
hashField
,
RedisValue
value
,
When
when
=
When
.
Always
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
{
WhenAlwaysOrNotExists
(
when
);
WhenAlwaysOrNotExists
(
when
);
...
@@ -447,6 +454,12 @@ public Task<bool> HashSetAsync(RedisKey key, RedisValue hashField, RedisValue va
...
@@ -447,6 +454,12 @@ public Task<bool> HashSetAsync(RedisKey key, RedisValue hashField, RedisValue va
return
ExecuteAsync
(
msg
,
ResultProcessor
.
Boolean
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
Boolean
);
}
}
public
Task
<
long
>
HashStringLengthAsync
(
RedisKey
key
,
RedisValue
hashField
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(
Database
,
flags
,
RedisCommand
.
HSTRLEN
,
key
,
hashField
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
Int64
);
}
public
Task
HashSetAsync
(
RedisKey
key
,
HashEntry
[]
hashFields
,
CommandFlags
flags
=
CommandFlags
.
None
)
public
Task
HashSetAsync
(
RedisKey
key
,
HashEntry
[]
hashFields
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
{
var
msg
=
GetHashSetMessage
(
key
,
hashFields
,
flags
);
var
msg
=
GetHashSetMessage
(
key
,
hashFields
,
flags
);
...
...
src/StackExchange.Redis/RedisFeatures.cs
View file @
b0a07a76
...
@@ -65,6 +65,11 @@ public RedisFeatures(Version version)
...
@@ -65,6 +65,11 @@ public RedisFeatures(Version version)
/// </summary>
/// </summary>
public
bool
ExpireOverwrite
=>
Version
>=
v2_1_3
;
public
bool
ExpireOverwrite
=>
Version
>=
v2_1_3
;
/// <summary>
/// Is HSTRLEN available?
/// </summary>
public
bool
HashStringLength
=>
Version
>=
v3_2_0
;
/// <summary>
/// <summary>
/// Does HDEL support varadic usage?
/// Does HDEL support varadic usage?
/// </summary>
/// </summary>
...
...
tests/StackExchange.Redis.Tests/DatabaseWrapperTests.cs
View file @
b0a07a76
...
@@ -166,6 +166,13 @@ public void HashSet_2()
...
@@ -166,6 +166,13 @@ public void HashSet_2()
mock
.
Verify
(
_
=>
_
.
HashSet
(
"prefix:key"
,
"hashField"
,
"value"
,
When
.
Exists
,
CommandFlags
.
None
));
mock
.
Verify
(
_
=>
_
.
HashSet
(
"prefix:key"
,
"hashField"
,
"value"
,
When
.
Exists
,
CommandFlags
.
None
));
}
}
[
Fact
]
public
void
HashStringLength
()
{
wrapper
.
HashStringLength
(
"key"
,
"field"
,
CommandFlags
.
None
);
mock
.
Verify
(
_
=>
_
.
HashStringLength
(
"prefix:key"
,
"field"
,
CommandFlags
.
None
));
}
[
Fact
]
[
Fact
]
public
void
HashValues
()
public
void
HashValues
()
{
{
...
...
tests/StackExchange.Redis.Tests/Strings.cs
View file @
b0a07a76
...
@@ -304,6 +304,38 @@ public async Task RangeString()
...
@@ -304,6 +304,38 @@ public async Task RangeString()
}
}
}
}
[
Fact
]
public
async
Task
HashStringLengthAsync
()
{
using
(
var
conn
=
Create
())
{
Skip
.
IfMissingFeature
(
conn
,
nameof
(
RedisFeatures
.
HashStringLength
),
r
=>
r
.
HashStringLength
);
var
database
=
conn
.
GetDatabase
();
var
key
=
Me
();
var
value
=
"hello world"
;
database
.
HashSet
(
key
,
"field"
,
value
);
var
resAsync
=
database
.
HashStringLengthAsync
(
key
,
"field"
);
var
resNonExistingAsync
=
database
.
HashStringLengthAsync
(
key
,
"non-existing-field"
);
Assert
.
Equal
(
value
.
Length
,
await
resAsync
);
Assert
.
Equal
(
0
,
await
resNonExistingAsync
);
}
}
[
Fact
]
public
void
HashStringLength
()
{
using
(
var
conn
=
Create
())
{
Skip
.
IfMissingFeature
(
conn
,
nameof
(
RedisFeatures
.
HashStringLength
),
r
=>
r
.
HashStringLength
);
var
database
=
conn
.
GetDatabase
();
var
key
=
Me
();
var
value
=
"hello world"
;
database
.
HashSet
(
key
,
"field"
,
value
);
Assert
.
Equal
(
value
.
Length
,
database
.
HashStringLength
(
key
,
"field"
));
Assert
.
Equal
(
0
,
database
.
HashStringLength
(
key
,
"non-existing-field"
));
}
}
private
static
byte
[]
Encode
(
string
value
)
=>
Encoding
.
UTF8
.
GetBytes
(
value
);
private
static
byte
[]
Encode
(
string
value
)
=>
Encoding
.
UTF8
.
GetBytes
(
value
);
private
static
string
Decode
(
byte
[]
value
)
=>
Encoding
.
UTF8
.
GetString
(
value
);
private
static
string
Decode
(
byte
[]
value
)
=>
Encoding
.
UTF8
.
GetString
(
value
);
}
}
...
...
tests/StackExchange.Redis.Tests/WrapperBaseTests.cs
View file @
b0a07a76
...
@@ -130,7 +130,14 @@ public void HashSetAsync_2()
...
@@ -130,7 +130,14 @@ public void HashSetAsync_2()
wrapper
.
HashSetAsync
(
"key"
,
"hashField"
,
"value"
,
When
.
Exists
,
CommandFlags
.
None
);
wrapper
.
HashSetAsync
(
"key"
,
"hashField"
,
"value"
,
When
.
Exists
,
CommandFlags
.
None
);
mock
.
Verify
(
_
=>
_
.
HashSetAsync
(
"prefix:key"
,
"hashField"
,
"value"
,
When
.
Exists
,
CommandFlags
.
None
));
mock
.
Verify
(
_
=>
_
.
HashSetAsync
(
"prefix:key"
,
"hashField"
,
"value"
,
When
.
Exists
,
CommandFlags
.
None
));
}
}
[
Fact
]
public
void
HashStringLengthAsync
()
{
wrapper
.
HashStringLengthAsync
(
"key"
,
"field"
,
CommandFlags
.
None
);
mock
.
Verify
(
_
=>
_
.
HashStringLengthAsync
(
"prefix:key"
,
"field"
,
CommandFlags
.
None
));
}
[
Fact
]
[
Fact
]
public
void
HashValuesAsync
()
public
void
HashValuesAsync
()
{
{
...
...
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