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
6b351b86
Commit
6b351b86
authored
Jul 25, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve TypedRedisValue.MultiBulk API - doesn't require a ToArray() now
parent
4de58246
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
10 deletions
+29
-10
RedisServer.cs
StackExchange.Redis.Server/RedisServer.cs
+1
-1
TypedRedisValue.cs
StackExchange.Redis.Server/TypedRedisValue.cs
+28
-9
No files found.
StackExchange.Redis.Server/RedisServer.cs
View file @
6b351b86
...
@@ -359,7 +359,7 @@ protected virtual TypedRedisValue Keys(RedisClient client, RedisRequest request)
...
@@ -359,7 +359,7 @@ protected virtual TypedRedisValue Keys(RedisClient client, RedisRequest request)
found
.
Add
(
TypedRedisValue
.
BulkString
(
key
.
AsRedisValue
()));
found
.
Add
(
TypedRedisValue
.
BulkString
(
key
.
AsRedisValue
()));
}
}
if
(
found
==
null
)
return
TypedRedisValue
.
EmptyArray
;
if
(
found
==
null
)
return
TypedRedisValue
.
EmptyArray
;
return
TypedRedisValue
.
MultiBulk
(
found
.
ToArray
()
);
return
TypedRedisValue
.
MultiBulk
(
found
);
}
}
protected
virtual
IEnumerable
<
RedisKey
>
Keys
(
int
database
,
RedisKey
pattern
)
=>
throw
new
NotSupportedException
();
protected
virtual
IEnumerable
<
RedisKey
>
Keys
(
int
database
,
RedisKey
pattern
)
=>
throw
new
NotSupportedException
();
...
...
StackExchange.Redis.Server/TypedRedisValue.cs
View file @
6b351b86
using
System
;
using
System
;
using
System.Buffers
;
using
System.Buffers
;
using
System.Collections.Generic
;
namespace
StackExchange.Redis
namespace
StackExchange.Redis
{
{
...
@@ -8,8 +9,15 @@ namespace StackExchange.Redis
...
@@ -8,8 +9,15 @@ namespace StackExchange.Redis
/// </summary>
/// </summary>
public
readonly
struct
TypedRedisValue
public
readonly
struct
TypedRedisValue
{
{
// note: if this ever becomes exposed on the public API, it should be made so that it clears;
// can't trust external callers to clear the space, and using recycle without that is dangerous
internal
static
TypedRedisValue
Rent
(
int
count
,
out
Span
<
TypedRedisValue
>
span
)
internal
static
TypedRedisValue
Rent
(
int
count
,
out
Span
<
TypedRedisValue
>
span
)
{
{
if
(
count
==
0
)
{
span
=
default
;
return
EmptyArray
;
}
var
arr
=
ArrayPool
<
TypedRedisValue
>.
Shared
.
Rent
(
count
);
var
arr
=
ArrayPool
<
TypedRedisValue
>.
Shared
.
Rent
(
count
);
span
=
new
Span
<
TypedRedisValue
>(
arr
,
0
,
count
);
span
=
new
Span
<
TypedRedisValue
>(
arr
,
0
,
count
);
return
new
TypedRedisValue
(
arr
,
count
);
return
new
TypedRedisValue
(
arr
,
count
);
...
@@ -63,8 +71,8 @@ public static TypedRedisValue SimpleString(string value)
...
@@ -63,8 +71,8 @@ public static TypedRedisValue SimpleString(string value)
public
static
TypedRedisValue
OK
{
get
;
}
=
SimpleString
(
"OK"
);
public
static
TypedRedisValue
OK
{
get
;
}
=
SimpleString
(
"OK"
);
internal
static
TypedRedisValue
Zero
{
get
;
}
=
Integer
(
0
);
internal
static
TypedRedisValue
Zero
{
get
;
}
=
Integer
(
0
);
internal
static
TypedRedisValue
One
{
get
;
}
=
Integer
(
1
);
internal
static
TypedRedisValue
One
{
get
;
}
=
Integer
(
1
);
internal
static
TypedRedisValue
NullArray
{
get
;
}
=
MultiBulk
(
null
);
internal
static
TypedRedisValue
NullArray
{
get
;
}
=
new
TypedRedisValue
((
TypedRedisValue
[])
null
,
0
);
internal
static
TypedRedisValue
EmptyArray
{
get
;
}
=
MultiBulk
(
Array
.
Empty
<
TypedRedisValue
>()
);
internal
static
TypedRedisValue
EmptyArray
{
get
;
}
=
new
TypedRedisValue
(
Array
.
Empty
<
TypedRedisValue
>(),
0
);
/// <summary>
/// <summary>
/// Gets the array elements as a span
/// Gets the array elements as a span
...
@@ -99,16 +107,27 @@ public static TypedRedisValue Integer(long value)
...
@@ -99,16 +107,27 @@ public static TypedRedisValue Integer(long value)
=>
new
TypedRedisValue
(
value
,
ResultType
.
Integer
);
=>
new
TypedRedisValue
(
value
,
ResultType
.
Integer
);
/// <summary>
/// <summary>
/// Initialize a TypedRedisValue from a
n array
/// Initialize a TypedRedisValue from a
span
/// </summary>
/// </summary>
public
static
TypedRedisValue
MultiBulk
(
TypedRedisValue
[]
items
)
public
static
TypedRedisValue
MultiBulk
(
ReadOnlySpan
<
TypedRedisValue
>
items
)
=>
new
TypedRedisValue
(
items
,
items
==
null
?
0
:
items
.
Length
);
{
if
(
items
.
IsEmpty
)
return
EmptyArray
;
var
result
=
Rent
(
items
.
Length
,
out
var
span
);
items
.
CopyTo
(
span
);
return
result
;
}
/// <summary>
/// <summary>
/// Initialize a TypedRedisValue from a
n oversized array
/// Initialize a TypedRedisValue from a
collection
/// </summary>
/// </summary>
public
static
TypedRedisValue
MultiBulk
(
TypedRedisValue
[]
oversizedItems
,
int
count
)
public
static
TypedRedisValue
MultiBulk
(
ICollection
<
TypedRedisValue
>
items
)
=>
new
TypedRedisValue
(
oversizedItems
,
count
);
{
if
(
items
==
null
)
return
NullArray
;
int
count
=
items
.
Count
;
if
(
count
==
0
)
return
EmptyArray
;
var
arr
=
ArrayPool
<
TypedRedisValue
>.
Shared
.
Rent
(
count
);
items
.
CopyTo
(
arr
,
0
);
return
new
TypedRedisValue
(
arr
,
count
);
}
/// <summary>
/// <summary>
/// Initialize a TypedRedisValue that represents a bulk string
/// Initialize a TypedRedisValue that represents a bulk string
...
...
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