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
8cc645dc
Commit
8cc645dc
authored
Aug 09, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve RedisFeatures text output
parent
a4d087f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
6 deletions
+59
-6
RedisFeaturesTests.cs
StackExchange.Redis.Tests/RedisFeaturesTests.cs
+30
-0
RedisFeatures.cs
StackExchange.Redis/StackExchange/Redis/RedisFeatures.cs
+29
-6
No files found.
StackExchange.Redis.Tests/RedisFeaturesTests.cs
0 → 100644
View file @
8cc645dc
using
System
;
using
Xunit
;
namespace
StackExchange.Redis.Tests
{
public
class
RedisFeaturesTests
{
[
Fact
]
public
void
ExecAbort
()
// a random one because it is fun
{
var
features
=
new
RedisFeatures
(
new
Version
(
2
,
9
));
var
s
=
features
.
ToString
();
Assert
.
True
(
features
.
ExecAbort
);
Assert
.
StartsWith
(
"Features in 2.9\r\n"
,
s
);
Assert
.
Contains
(
"ExecAbort: True\r\n"
,
s
);
features
=
new
RedisFeatures
(
new
Version
(
2
,
9
,
5
));
s
=
features
.
ToString
();
Assert
.
False
(
features
.
ExecAbort
);
Assert
.
StartsWith
(
"Features in 2.9.5\r\n"
,
s
);
Assert
.
Contains
(
"ExecAbort: False\r\n"
,
s
);
features
=
new
RedisFeatures
(
new
Version
(
3
,
0
));
s
=
features
.
ToString
();
Assert
.
True
(
features
.
ExecAbort
);
Assert
.
StartsWith
(
"Features in 3.0\r\n"
,
s
);
Assert
.
Contains
(
"ExecAbort: True\r\n"
,
s
);
}
}
}
StackExchange.Redis/StackExchange/Redis/RedisFeatures.cs
View file @
8cc645dc
using
System
;
using
System
;
using
System.Linq
;
using
System.Reflection
;
using
System.Text
;
using
System.Text
;
namespace
StackExchange.Redis
namespace
StackExchange.Redis
...
@@ -32,6 +34,7 @@ public struct RedisFeatures
...
@@ -32,6 +34,7 @@ public struct RedisFeatures
v4_9_1
=
new
Version
(
4
,
9
,
1
);
// 5.0 RC1 is version 4.9.1
v4_9_1
=
new
Version
(
4
,
9
,
1
);
// 5.0 RC1 is version 4.9.1
private
readonly
Version
version
;
private
readonly
Version
version
;
/// <summary>
/// <summary>
/// Create a new RedisFeatures instance for the given version
/// Create a new RedisFeatures instance for the given version
/// </summary>
/// </summary>
...
@@ -166,13 +169,33 @@ public RedisFeatures(Version version)
...
@@ -166,13 +169,33 @@ public RedisFeatures(Version version)
/// </summary>
/// </summary>
public
override
string
ToString
()
public
override
string
ToString
()
{
{
var
sb
=
new
StringBuilder
().
Append
(
"Features in "
).
Append
(
Version
).
AppendLine
()
var
v
=
Version
;
// the docs lie: Version.ToString(fieldCount) only supports 0-2 fields
.
Append
(
"ExpireOverwrite: "
).
Append
(
ExpireOverwrite
).
AppendLine
()
var
sb
=
new
StringBuilder
().
Append
(
"Features in "
).
Append
(
v
.
Major
).
Append
(
'.'
).
Append
(
v
.
Minor
);
.
Append
(
"Persist: "
).
Append
(
Persist
).
AppendLine
();
if
(
v
.
Revision
>=
0
)
sb
.
Append
(
'.'
).
Append
(
v
.
Revision
);
if
(
v
.
Build
>=
0
)
sb
.
Append
(
'.'
).
Append
(
v
.
Build
);
sb
.
AppendLine
();
object
boxed
=
this
;
foreach
(
var
prop
in
s_props
)
{
sb
.
Append
(
prop
.
Name
).
Append
(
": "
).
Append
(
prop
.
GetValue
(
boxed
)).
AppendLine
();
}
return
sb
.
ToString
();
return
sb
.
ToString
();
}
}
// 2.9.5 (cluster beta 1) has a bug in EXECABORT re MOVED and ASK; it only affects cluster, but
// frankly if you aren't playing with cluster, why are you using 2.9.5 in the first place?
private
static
readonly
PropertyInfo
[]
s_props
=
(
from
prop
in
typeof
(
RedisFeatures
).
GetProperties
(
BindingFlags
.
Instance
|
BindingFlags
.
Public
)
where
prop
.
PropertyType
==
typeof
(
bool
)
let
indexers
=
prop
.
GetIndexParameters
()
where
indexers
==
null
||
indexers
.
Length
==
0
orderby
prop
.
Name
select
prop
).
ToArray
();
/// <summary>Returns the hash code for this instance.</summary>
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
public
override
int
GetHashCode
()
=>
Version
.
GetHashCode
();
/// <summary>Indicates whether this instance and a specified object are equal.</summary>
/// <returns>true if <paramref name="obj" /> and this instance are the same type and represent the same value; otherwise, false. </returns>
/// <param name="obj">The object to compare with the current instance. </param>
public
override
bool
Equals
(
object
obj
)
=>
obj
is
RedisFeatures
f
&&
f
.
Version
==
Version
;
}
}
}
}
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