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
b65bb3e3
Commit
b65bb3e3
authored
Jul 28, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup: TypedRedisValue + docs
parent
6252d90e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
18 deletions
+29
-18
TypedRedisValue.cs
StackExchange.Redis.Server/TypedRedisValue.cs
+29
-18
No files found.
StackExchange.Redis.Server/TypedRedisValue.cs
View file @
b65bb3e3
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
namespace
StackExchange.Redis
namespace
StackExchange.Redis
{
{
/// <summary>
/// <summary>
/// A
RedisValue with an eplicit encoding type, which could represent an array of items
/// A
<see cref="RedisValue"/> with an eplicit encoding type, which could represent an array of items.
/// </summary>
/// </summary>
public
readonly
struct
TypedRedisValue
public
readonly
struct
TypedRedisValue
{
{
...
@@ -24,29 +24,31 @@ internal static TypedRedisValue Rent(int count, out Span<TypedRedisValue> span)
...
@@ -24,29 +24,31 @@ internal static TypedRedisValue Rent(int count, out Span<TypedRedisValue> span)
}
}
/// <summary>
/// <summary>
/// An invalid empty value that has no type
/// An invalid empty value that has no type
.
/// </summary>
/// </summary>
public
static
TypedRedisValue
Nil
=>
default
;
public
static
TypedRedisValue
Nil
=>
default
;
/// <summary>
/// <summary>
/// Returns whether this value is an invalid empty value
/// Returns whether this value is an invalid empty value
.
/// </summary>
/// </summary>
public
bool
IsNil
=>
Type
==
ResultType
.
None
;
public
bool
IsNil
=>
Type
==
ResultType
.
None
;
/// <summary>
/// <summary>
/// Returns whether this value represents a null array
/// Returns whether this value represents a null array
.
/// </summary>
/// </summary>
public
bool
IsNullArray
=>
Type
==
ResultType
.
MultiBulk
&&
_value
.
DirectObject
==
null
;
public
bool
IsNullArray
=>
Type
==
ResultType
.
MultiBulk
&&
_value
.
DirectObject
==
null
;
private
readonly
RedisValue
_value
;
private
readonly
RedisValue
_value
;
/// <summary>
/// <summary>
/// The type of value being represented
/// The type of value being represented
.
/// </summary>
/// </summary>
public
ResultType
Type
{
get
;
}
public
ResultType
Type
{
get
;
}
/// <summary>
/// <summary>
/// Initialize a TypedRedisValue from a value and optionally a type
/// Initialize a TypedRedisValue from a value and optionally a type
.
/// </summary>
/// </summary>
/// <param name="value">The value to initialize.</param>
/// <param name="type">The type of <paramref name="value"/>.</param>
private
TypedRedisValue
(
RedisValue
value
,
ResultType
?
type
=
null
)
private
TypedRedisValue
(
RedisValue
value
,
ResultType
?
type
=
null
)
{
{
Type
=
type
??
(
value
.
IsInteger
?
ResultType
.
Integer
:
ResultType
.
BulkString
);
Type
=
type
??
(
value
.
IsInteger
?
ResultType
.
Integer
:
ResultType
.
BulkString
);
...
@@ -54,14 +56,16 @@ private TypedRedisValue(RedisValue value, ResultType? type = null)
...
@@ -54,14 +56,16 @@ private TypedRedisValue(RedisValue value, ResultType? type = null)
}
}
/// <summary>
/// <summary>
/// Initialize a TypedRedisValue that represents an error
/// Initialize a TypedRedisValue that represents an error
.
/// </summary>
/// </summary>
/// <param name="value">The error message.</param>
public
static
TypedRedisValue
Error
(
string
value
)
public
static
TypedRedisValue
Error
(
string
value
)
=>
new
TypedRedisValue
(
value
,
ResultType
.
Error
);
=>
new
TypedRedisValue
(
value
,
ResultType
.
Error
);
/// <summary>
/// <summary>
/// Initialize a TypedRedisValue that represents a simple string
/// Initialize a TypedRedisValue that represents a simple string
.
/// </summary>
/// </summary>
/// <param name="value">The string value.</param>
public
static
TypedRedisValue
SimpleString
(
string
value
)
public
static
TypedRedisValue
SimpleString
(
string
value
)
=>
new
TypedRedisValue
(
value
,
ResultType
.
SimpleString
);
=>
new
TypedRedisValue
(
value
,
ResultType
.
SimpleString
);
...
@@ -101,14 +105,16 @@ public ArraySegment<TypedRedisValue> Segment
...
@@ -101,14 +105,16 @@ public ArraySegment<TypedRedisValue> Segment
}
}
/// <summary>
/// <summary>
/// Initialize a
TypedRedisValue that represents an integer
/// Initialize a
<see cref="TypedRedisValue"/> that represents an integer.
/// </summary>
/// </summary>
/// <param name="value">The value to initialize from.</param>
public
static
TypedRedisValue
Integer
(
long
value
)
public
static
TypedRedisValue
Integer
(
long
value
)
=>
new
TypedRedisValue
(
value
,
ResultType
.
Integer
);
=>
new
TypedRedisValue
(
value
,
ResultType
.
Integer
);
/// <summary>
/// <summary>
/// Initialize a
TypedRedisValue from a span
/// Initialize a
<see cref="TypedRedisValue"/> from a <see cref="ReadOnlySpan{TypedRedisValue}"/>.
/// </summary>
/// </summary>
/// <param name="items">The items to intialize a value from.</param>
public
static
TypedRedisValue
MultiBulk
(
ReadOnlySpan
<
TypedRedisValue
>
items
)
public
static
TypedRedisValue
MultiBulk
(
ReadOnlySpan
<
TypedRedisValue
>
items
)
{
{
if
(
items
.
IsEmpty
)
return
EmptyArray
;
if
(
items
.
IsEmpty
)
return
EmptyArray
;
...
@@ -116,9 +122,11 @@ public static TypedRedisValue MultiBulk(ReadOnlySpan<TypedRedisValue> items)
...
@@ -116,9 +122,11 @@ public static TypedRedisValue MultiBulk(ReadOnlySpan<TypedRedisValue> items)
items
.
CopyTo
(
span
);
items
.
CopyTo
(
span
);
return
result
;
return
result
;
}
}
/// <summary>
/// <summary>
/// Initialize a
TypedRedisValue from a collection
/// Initialize a
<see cref="TypedRedisValue"/> from a collection.
/// </summary>
/// </summary>
/// <param name="items">The items to intialize a value from.</param>
public
static
TypedRedisValue
MultiBulk
(
ICollection
<
TypedRedisValue
>
items
)
public
static
TypedRedisValue
MultiBulk
(
ICollection
<
TypedRedisValue
>
items
)
{
{
if
(
items
==
null
)
return
NullArray
;
if
(
items
==
null
)
return
NullArray
;
...
@@ -130,8 +138,9 @@ public static TypedRedisValue MultiBulk(ICollection<TypedRedisValue> items)
...
@@ -130,8 +138,9 @@ public static TypedRedisValue MultiBulk(ICollection<TypedRedisValue> items)
}
}
/// <summary>
/// <summary>
/// Initialize a
TypedRedisValue that represents a bulk string
/// Initialize a
<see cref="TypedRedisValue"/> that represents a bulk string.
/// </summary>
/// </summary>
/// <param name="value">The value to initialize from.</param>
public
static
TypedRedisValue
BulkString
(
RedisValue
value
)
public
static
TypedRedisValue
BulkString
(
RedisValue
value
)
=>
new
TypedRedisValue
(
value
,
ResultType
.
BulkString
);
=>
new
TypedRedisValue
(
value
,
ResultType
.
BulkString
);
...
@@ -149,6 +158,7 @@ private TypedRedisValue(TypedRedisValue[] oversizedItems, int count)
...
@@ -149,6 +158,7 @@ private TypedRedisValue(TypedRedisValue[] oversizedItems, int count)
_value
=
new
RedisValue
(
oversizedItems
,
count
);
_value
=
new
RedisValue
(
oversizedItems
,
count
);
Type
=
ResultType
.
MultiBulk
;
Type
=
ResultType
.
MultiBulk
;
}
}
internal
void
Recycle
(
int
limit
=
-
1
)
internal
void
Recycle
(
int
limit
=
-
1
)
{
{
if
(
_value
.
DirectObject
is
TypedRedisValue
[]
arr
)
if
(
_value
.
DirectObject
is
TypedRedisValue
[]
arr
)
...
@@ -163,12 +173,12 @@ internal void Recycle(int limit = -1)
...
@@ -163,12 +173,12 @@ internal void Recycle(int limit = -1)
}
}
/// <summary>
/// <summary>
/// Get the underlying
value assuming that it is a valid type with a meaningful value
/// Get the underlying
<see cref="RedisValue"/> assuming that it is a valid type with a meaningful value.
/// </summary>
/// </summary>
internal
RedisValue
AsRedisValue
()
=>
Type
==
ResultType
.
MultiBulk
?
default
:
_value
;
internal
RedisValue
AsRedisValue
()
=>
Type
==
ResultType
.
MultiBulk
?
default
:
_value
;
/// <summary>
/// <summary>
/// Obtain the value as a string
/// Obtain the value as a string
.
/// </summary>
/// </summary>
public
override
string
ToString
()
public
override
string
ToString
()
{
{
...
@@ -187,13 +197,14 @@ public override string ToString()
...
@@ -187,13 +197,14 @@ public override string ToString()
}
}
/// <summary>
/// <summary>
/// Not supported
/// Not supported
.
/// </summary>
/// </summary>
public
override
int
GetHashCode
()
=>
throw
new
NotSupportedException
();
public
override
int
GetHashCode
()
=>
throw
new
NotSupportedException
();
/// <summary>
/// <summary>
/// Not supported
/// Not supported
.
/// </summary>
/// </summary>
/// <param name="obj">The object to compare to.</param>
public
override
bool
Equals
(
object
obj
)
=>
throw
new
NotSupportedException
();
public
override
bool
Equals
(
object
obj
)
=>
throw
new
NotSupportedException
();
}
}
}
}
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