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
41fd4a6b
Commit
41fd4a6b
authored
Apr 30, 2017
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Client should only *demand* IDatabaseAsync, but *allow* IDatabase
parent
ddbcdb83
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
Client.cs
NRediSearch/Client.cs
+16
-12
No files found.
NRediSearch/Client.cs
View file @
41fd4a6b
...
@@ -51,14 +51,18 @@ private static void SerializeRedisArgs(IndexOptions flags, List<object> args)
...
@@ -51,14 +51,18 @@ private static void SerializeRedisArgs(IndexOptions flags, List<object> args)
args
.
Add
(
"NOSCOREIDX"
.
Literal
());
args
.
Add
(
"NOSCOREIDX"
.
Literal
());
}
}
}
}
IDatabase
_db
;
private
readonly
IDatabaseAsync
_db
;
private
object
_boxedIndexName
;
private
IDatabase
DbSync
=>
(
_db
as
IDatabase
)
??
throw
new
InvalidOperationException
(
"Synchronous operations are not available on this database instance"
);
private
readonly
object
_boxedIndexName
;
public
RedisKey
IndexName
=>
(
RedisKey
)
_boxedIndexName
;
public
RedisKey
IndexName
=>
(
RedisKey
)
_boxedIndexName
;
public
Client
(
RedisKey
indexName
,
IDatabase
db
)
public
Client
(
RedisKey
indexName
,
IDatabase
Async
db
)
{
{
_db
=
db
;
_db
=
db
??
throw
new
ArgumentNullException
(
nameof
(
db
))
;
_boxedIndexName
=
indexName
;
// only box once, not per-command
_boxedIndexName
=
indexName
;
// only box once, not per-command
}
}
public
Client
(
RedisKey
indexName
,
IDatabase
db
)
:
this
(
indexName
,
(
IDatabaseAsync
)
db
)
{
}
/// <summary>
/// <summary>
/// Create the index definition in redis
/// Create the index definition in redis
...
@@ -79,7 +83,7 @@ public bool CreateIndex(Schema schema, IndexOptions options)
...
@@ -79,7 +83,7 @@ public bool CreateIndex(Schema schema, IndexOptions options)
f
.
SerializeRedisArgs
(
args
);
f
.
SerializeRedisArgs
(
args
);
}
}
return
(
string
)
_db
.
Execute
(
"FT.CREATE"
,
args
)
==
"OK"
;
return
(
string
)
DbSync
.
Execute
(
"FT.CREATE"
,
args
)
==
"OK"
;
}
}
/// <summary>
/// <summary>
...
@@ -115,7 +119,7 @@ public SearchResult Search(Query q)
...
@@ -115,7 +119,7 @@ public SearchResult Search(Query q)
args
.
Add
(
_boxedIndexName
);
args
.
Add
(
_boxedIndexName
);
q
.
SerializeRedisArgs
(
args
);
q
.
SerializeRedisArgs
(
args
);
var
resp
=
(
RedisResult
[])
_db
.
Execute
(
"FT.SEARCH"
,
args
);
var
resp
=
(
RedisResult
[])
DbSync
.
Execute
(
"FT.SEARCH"
,
args
);
return
new
SearchResult
(
resp
,
!
q
.
NoContent
,
q
.
WithScores
,
q
.
WithPayloads
);
return
new
SearchResult
(
resp
,
!
q
.
NoContent
,
q
.
WithScores
,
q
.
WithPayloads
);
}
}
...
@@ -146,7 +150,7 @@ public async Task<SearchResult> SearchAsync(Query q)
...
@@ -146,7 +150,7 @@ public async Task<SearchResult> SearchAsync(Query q)
public
bool
AddDocument
(
string
docId
,
Dictionary
<
string
,
RedisValue
>
fields
,
double
score
=
1.0
,
bool
noSave
=
false
,
bool
replace
=
false
,
byte
[]
payload
=
null
)
public
bool
AddDocument
(
string
docId
,
Dictionary
<
string
,
RedisValue
>
fields
,
double
score
=
1.0
,
bool
noSave
=
false
,
bool
replace
=
false
,
byte
[]
payload
=
null
)
{
{
var
args
=
BuildAddDocumentArgs
(
docId
,
fields
,
score
,
noSave
,
replace
,
payload
);
var
args
=
BuildAddDocumentArgs
(
docId
,
fields
,
score
,
noSave
,
replace
,
payload
);
return
(
string
)
_db
.
Execute
(
"FT.ADD"
,
args
)
==
"OK"
;
return
(
string
)
DbSync
.
Execute
(
"FT.ADD"
,
args
)
==
"OK"
;
}
}
/// <summary>
/// <summary>
...
@@ -217,7 +221,7 @@ public bool AddHash(string docId, double score, bool replace)
...
@@ -217,7 +221,7 @@ public bool AddHash(string docId, double score, bool replace)
{
{
args
.
Add
(
"REPLACE"
.
Literal
());
args
.
Add
(
"REPLACE"
.
Literal
());
}
}
return
(
string
)
_db
.
Execute
(
"FT.ADDHASH"
,
args
)
==
"OK"
;
return
(
string
)
DbSync
.
Execute
(
"FT.ADDHASH"
,
args
)
==
"OK"
;
}
}
/// <summary>
/// <summary>
/// Index a document already in redis as a HASH key.
/// Index a document already in redis as a HASH key.
...
@@ -243,7 +247,7 @@ public async Task<bool> AddHashAsync(string docId, double score, bool replace)
...
@@ -243,7 +247,7 @@ public async Task<bool> AddHashAsync(string docId, double score, bool replace)
/// <returns>a map of key/value pairs</returns>
/// <returns>a map of key/value pairs</returns>
public
Dictionary
<
string
,
RedisValue
>
GetInfo
()
public
Dictionary
<
string
,
RedisValue
>
GetInfo
()
{
{
return
ParseGetInfo
(
_db
.
Execute
(
"FT.INFO"
,
_boxedIndexName
));
return
ParseGetInfo
(
DbSync
.
Execute
(
"FT.INFO"
,
_boxedIndexName
));
}
}
/// <summary>
/// <summary>
/// Get the index info, including memory consumption and other statistics.
/// Get the index info, including memory consumption and other statistics.
...
@@ -274,7 +278,7 @@ public async Task<bool> AddHashAsync(string docId, double score, bool replace)
...
@@ -274,7 +278,7 @@ public async Task<bool> AddHashAsync(string docId, double score, bool replace)
/// <returns>true if it has been deleted, false if it did not exist</returns>
/// <returns>true if it has been deleted, false if it did not exist</returns>
public
bool
DeleteDocument
(
string
docId
)
public
bool
DeleteDocument
(
string
docId
)
{
{
return
(
long
)
_db
.
Execute
(
"FT.DEL"
,
_boxedIndexName
,
docId
)
==
1
;
return
(
long
)
DbSync
.
Execute
(
"FT.DEL"
,
_boxedIndexName
,
docId
)
==
1
;
}
}
/// <summary>
/// <summary>
...
@@ -293,7 +297,7 @@ public async Task<bool> DeleteDocumentAsync(string docId)
...
@@ -293,7 +297,7 @@ public async Task<bool> DeleteDocumentAsync(string docId)
/// <returns>true on success</returns>
/// <returns>true on success</returns>
public
bool
DropIndex
()
public
bool
DropIndex
()
{
{
return
(
string
)
_db
.
Execute
(
"FT.DROP"
,
_boxedIndexName
)
==
"OK"
;
return
(
string
)
DbSync
.
Execute
(
"FT.DROP"
,
_boxedIndexName
)
==
"OK"
;
}
}
/// <summary>
/// <summary>
/// Drop the index and all associated keys, including documents
/// Drop the index and all associated keys, including documents
...
@@ -309,7 +313,7 @@ public async Task<bool> DropIndexAsync()
...
@@ -309,7 +313,7 @@ public async Task<bool> DropIndexAsync()
/// </summary>
/// </summary>
public
long
OptimizeIndex
()
public
long
OptimizeIndex
()
{
{
return
(
long
)
_db
.
Execute
(
"FT.OPTIMIZE"
,
_boxedIndexName
);
return
(
long
)
DbSync
.
Execute
(
"FT.OPTIMIZE"
,
_boxedIndexName
);
}
}
/// <summary>
/// <summary>
...
...
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