-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
65 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* RequestPrefIt.h | ||
* | ||
* Request listener for command "prefit" | ||
* Prefix iterator | ||
* | ||
* @author valmat <[email protected]> | ||
* @github https://github.com/valmat/rocksserver | ||
*/ | ||
|
||
|
||
namespace RocksServer { | ||
|
||
class RequestPrefIt : public RequestBase<ProtocolInGet, ProtocolOut> | ||
{ | ||
public: | ||
RequestPrefIt(RocksDBWrapper &rdb) : _rdb(rdb) {} | ||
|
||
/** | ||
* Runs request listener | ||
* @param protocol in object | ||
* @param protocol out object | ||
*/ | ||
virtual void run(const ProtocolInGet &in, const ProtocolOut &out) override | ||
{ | ||
if(!in.check()) { | ||
out.setFailValue(); | ||
return; | ||
} | ||
|
||
auto prefix = in.key(); | ||
std::unique_ptr<rocksdb::Iterator> iter(_rdb->NewIterator(rocksdb::ReadOptions())); | ||
|
||
// filling buffer | ||
for (iter->Seek(prefix); iter->Valid() && iter->key().starts_with(prefix); iter->Next()) { | ||
if(iter->status().ok()) { | ||
out.setPair(iter->key(), iter->value()); | ||
} else { | ||
out.setFailPair(iter->key()); | ||
} | ||
} | ||
|
||
} | ||
|
||
virtual ~RequestPrefIt() {} | ||
private: | ||
RocksDBWrapper& _rdb; | ||
}; | ||
|
||
} |