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
79c023b4
Commit
79c023b4
authored
Apr 30, 2017
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow Execute to take lists rather than just arrays - avoids having to call ToArray()
parent
bd20a4bc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
37 deletions
+31
-37
Client.cs
NRediSearch/Client.cs
+9
-18
IDatabase.cs
StackExchange.Redis/StackExchange/Redis/IDatabase.cs
+1
-1
DatabaseWrapper.cs
.../StackExchange/Redis/KeyspaceIsolation/DatabaseWrapper.cs
+1
-1
WrapperBase.cs
...edis/StackExchange/Redis/KeyspaceIsolation/WrapperBase.cs
+14
-9
RedisDatabase.cs
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
+6
-8
No files found.
NRediSearch/Client.cs
View file @
79c023b4
...
...
@@ -78,7 +78,7 @@ public bool CreateIndex(Schema schema, IndexOptions options)
f
.
SerializeRedisArgs
(
args
);
}
return
(
string
)
_db
.
Execute
(
"FT.CREATE"
,
args
.
ToArray
()
)
==
"OK"
;
return
(
string
)
_db
.
Execute
(
"FT.CREATE"
,
args
)
==
"OK"
;
}
/// <summary>
...
...
@@ -92,7 +92,7 @@ public SearchResult Search(Query q)
args
.
Add
(
_boxedIndexName
);
q
.
SerializeRedisArgs
(
args
);
var
resp
=
(
RedisResult
[])
_db
.
Execute
(
"FT.SEARCH"
,
args
.
ToArray
()
);
var
resp
=
(
RedisResult
[])
_db
.
Execute
(
"FT.SEARCH"
,
args
);
return
new
SearchResult
(
resp
,
!
q
.
NoContent
,
q
.
WithScores
,
q
.
WithPayloads
);
}
...
...
@@ -105,7 +105,7 @@ public SearchResult Search(Query q)
/// <param name="noSave">if set, we only index the document and do not save its contents. This allows fetching just doc ids</param>
/// <param name="replace">if set, and the document already exists, we reindex and update it</param>
/// <param name="payload">if set, we can save a payload in the index to be retrieved or evaluated by scoring functions on the server</param>
public
bool
AddDocument
(
string
docId
,
double
score
,
Dictionary
<
string
,
RedisValue
>
fields
,
bool
noSave
,
bool
replace
,
byte
[]
payload
)
public
bool
AddDocument
(
string
docId
,
Dictionary
<
string
,
RedisValue
>
fields
,
double
score
=
1.0
,
bool
noSave
=
false
,
bool
replace
=
false
,
byte
[]
payload
=
null
)
{
var
args
=
new
List
<
object
>
{
_boxedIndexName
,
docId
,
score
};
if
(
noSave
)
...
...
@@ -130,21 +130,14 @@ public bool AddDocument(string docId, double score, Dictionary<string, RedisValu
args
.
Add
(
ent
.
Value
);
}
return
(
string
)
_db
.
Execute
(
"FT.ADD"
,
args
.
ToArray
()
)
==
"OK"
;
return
(
string
)
_db
.
Execute
(
"FT.ADD"
,
args
)
==
"OK"
;
}
/// <summary>
/// replaceDocument is a convenience for calling addDocument with replace=true
/// </summary>
public
bool
ReplaceDocument
(
string
docId
,
double
score
,
Dictionary
<
string
,
RedisValue
>
fields
)
=>
AddDocument
(
docId
,
score
,
fields
,
false
,
true
,
null
);
/** See above */
public
bool
AddDocument
(
string
docId
,
double
score
,
Dictionary
<
string
,
RedisValue
>
fields
)
=>
AddDocument
(
docId
,
score
,
fields
,
false
,
false
,
null
);
/** See above */
public
bool
AddDocument
(
string
docId
,
Dictionary
<
string
,
RedisValue
>
fields
)
=>
AddDocument
(
docId
,
1
,
fields
,
false
,
false
,
null
);
public
bool
ReplaceDocument
(
string
docId
,
Dictionary
<
string
,
RedisValue
>
fields
,
double
score
=
1.0
,
byte
[]
payload
=
null
)
=>
AddDocument
(
docId
,
fields
,
score
,
false
,
true
,
payload
);
/// <summary>
/// Index a document already in redis as a HASH key.
...
...
@@ -162,7 +155,7 @@ public bool AddHash(string docId, double score, bool replace)
args
.
Add
(
"REPLACE"
.
Literal
());
}
return
(
string
)
_db
.
Execute
(
"FT.ADDHASH"
,
args
.
ToArray
()
)
==
"OK"
;
return
(
string
)
_db
.
Execute
(
"FT.ADDHASH"
,
args
)
==
"OK"
;
}
/// <summary>
...
...
@@ -191,8 +184,7 @@ public bool AddHash(string docId, double score, bool replace)
/// <returns>true if it has been deleted, false if it did not exist</returns>
public
bool
DeleteDocument
(
string
docId
)
{
long
r
=
(
long
)
_db
.
Execute
(
"FT.DEL"
,
_boxedIndexName
,
docId
);
return
r
==
1
;
return
(
long
)
_db
.
Execute
(
"FT.DEL"
,
_boxedIndexName
,
docId
)
==
1
;
}
/// <summary>
...
...
@@ -209,8 +201,7 @@ public bool DropIndex()
/// </summary>
public
long
OptimizeIndex
()
{
long
ret
=
(
long
)
_db
.
Execute
(
"FT.OPTIMIZE"
,
_boxedIndexName
);
return
ret
;
return
(
long
)
_db
.
Execute
(
"FT.OPTIMIZE"
,
_boxedIndexName
);
}
}
}
StackExchange.Redis/StackExchange/Redis/IDatabase.cs
View file @
79c023b4
...
...
@@ -547,7 +547,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// a direct API
/// </summary>
/// <returns>A dynamic representation of the command's result</returns>
RedisResult
Execute
(
string
command
,
object
[]
args
,
CommandFlags
flags
=
CommandFlags
.
None
);
RedisResult
Execute
(
string
command
,
ICollection
<
object
>
args
,
CommandFlags
flags
=
CommandFlags
.
None
);
/// <summary>
...
...
StackExchange.Redis/StackExchange/Redis/KeyspaceIsolation/DatabaseWrapper.cs
View file @
79c023b4
...
...
@@ -363,7 +363,7 @@ public long Publish(RedisChannel channel, RedisValue message, CommandFlags flags
public
RedisResult
Execute
(
string
command
,
params
object
[]
args
)
=>
Execute
(
command
,
args
,
CommandFlags
.
None
);
public
RedisResult
Execute
(
string
command
,
object
[]
args
,
CommandFlags
flags
=
CommandFlags
.
None
)
public
RedisResult
Execute
(
string
command
,
ICollection
<
object
>
args
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
return
Inner
.
Execute
(
command
,
ToInner
(
args
),
flags
);
}
...
...
StackExchange.Redis/StackExchange/Redis/KeyspaceIsolation/WrapperBase.cs
View file @
79c023b4
...
...
@@ -713,23 +713,28 @@ protected RedisKey ToInnerOrDefault(RedisKey outer)
return
ToInner
(
outer
);
}
}
protected
object
[]
ToInner
(
object
[]
args
)
protected
ICollection
<
object
>
ToInner
(
ICollection
<
object
>
args
)
{
if
(
args
!=
null
&&
args
.
Any
(
x
=>
x
is
RedisKey
||
x
is
RedisChannel
))
{
var
withPrefix
=
new
object
[
args
.
Length
];
for
(
int
i
=
0
;
i
<
args
.
Length
;
i
++)
var
withPrefix
=
new
object
[
args
.
Count
];
int
i
=
0
;
foreach
(
var
oldArg
in
args
)
{
var
arg
=
args
[
i
]
;
if
(
a
rg
is
RedisKey
)
object
newArg
;
if
(
oldA
rg
is
RedisKey
)
{
arg
=
ToInner
((
RedisKey
)
a
rg
);
newArg
=
ToInner
((
RedisKey
)
oldA
rg
);
}
else
if
(
a
rg
is
RedisChannel
)
else
if
(
oldA
rg
is
RedisChannel
)
{
arg
=
ToInner
((
RedisChannel
)
a
rg
);
newArg
=
ToInner
((
RedisChannel
)
oldA
rg
);
}
withPrefix
[
i
]
=
arg
;
else
{
newArg
=
oldArg
;
}
withPrefix
[
i
++]
=
newArg
;
}
args
=
withPrefix
;
}
...
...
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
View file @
79c023b4
...
...
@@ -1061,7 +1061,7 @@ public RedisResult ScriptEvaluate(string script, RedisKey[] keys = null, RedisVa
}
public
RedisResult
Execute
(
string
command
,
params
object
[]
args
)
=>
Execute
(
command
,
args
,
CommandFlags
.
None
);
public
RedisResult
Execute
(
string
command
,
object
[]
args
,
CommandFlags
flags
=
CommandFlags
.
None
)
public
RedisResult
Execute
(
string
command
,
ICollection
<
object
>
args
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
new
ExecuteMessage
(
Database
,
flags
,
command
,
args
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
ScriptResult
);
...
...
@@ -2447,18 +2447,17 @@ private sealed class ExecuteMessage : Message
{
private
readonly
string
_command
;
private
static
readonly
object
[]
NoArgs
=
new
object
[
0
];
private
readonly
object
[]
args
;
public
ExecuteMessage
(
int
db
,
CommandFlags
flags
,
string
command
,
object
[]
args
)
:
base
(
db
,
flags
,
RedisCommand
.
UNKNOWN
)
private
readonly
ICollection
<
object
>
args
;
public
ExecuteMessage
(
int
db
,
CommandFlags
flags
,
string
command
,
ICollection
<
object
>
args
)
:
base
(
db
,
flags
,
RedisCommand
.
UNKNOWN
)
{
_command
=
command
;
this
.
args
=
args
??
NoArgs
;
}
internal
override
void
WriteImpl
(
PhysicalConnection
physical
)
{
physical
.
WriteHeader
(
_command
,
args
.
Length
);
for
(
int
i
=
0
;
i
<
args
.
Length
;
i
++
)
physical
.
WriteHeader
(
_command
,
args
.
Count
);
for
each
(
object
arg
in
args
)
{
object
arg
=
args
[
i
];
if
(
arg
is
RedisKey
)
{
physical
.
Write
((
RedisKey
)
arg
);
...
...
@@ -2478,9 +2477,8 @@ internal override void WriteImpl(PhysicalConnection physical)
public
override
int
GetHashSlot
(
ServerSelectionStrategy
serverSelectionStrategy
)
{
int
slot
=
ServerSelectionStrategy
.
NoSlot
;
for
(
int
i
=
0
;
i
<
args
.
Length
;
i
++
)
for
each
(
object
arg
in
args
)
{
object
arg
=
args
[
i
];
if
(
arg
is
RedisKey
)
{
slot
=
serverSelectionStrategy
.
CombineSlot
(
slot
,
(
RedisKey
)
arg
);
...
...
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