mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-17 11:45:50 +00:00
Implement SSCAN Redis command.
This commit is contained in:
parent
731582d8fe
commit
9949c273a1
4 changed files with 30 additions and 6 deletions
|
@ -133,4 +133,8 @@ namespace redis {
|
|||
auto Command::hscan (boost::string_ref parKey) -> hscan_range {
|
||||
return hscan_range(hscan_iterator(this, parKey, false), hscan_iterator(this, parKey, true));
|
||||
}
|
||||
|
||||
auto Command::sscan (boost::string_ref parKey) -> sscan_range {
|
||||
return sscan_range(sscan_iterator(this, parKey, false), sscan_iterator(this, parKey, true));
|
||||
}
|
||||
} //namespace redis
|
||||
|
|
|
@ -41,6 +41,8 @@ namespace redis {
|
|||
typedef boost::iterator_range<scan_iterator> scan_range;
|
||||
typedef ScanIterator<ScanPairs<std::pair<std::string, std::string>>> hscan_iterator;
|
||||
typedef boost::iterator_range<hscan_iterator> hscan_range;
|
||||
typedef ScanIterator<ScanSingleValuesInKey<std::string>> sscan_iterator;
|
||||
typedef boost::iterator_range<sscan_iterator> sscan_range;
|
||||
|
||||
Command ( std::string&& parAddress, uint16_t parPort );
|
||||
~Command ( void ) noexcept;
|
||||
|
@ -56,6 +58,7 @@ namespace redis {
|
|||
//Single Redis command wrappers
|
||||
scan_range scan ( void );
|
||||
hscan_range hscan ( boost::string_ref parKey );
|
||||
sscan_range sscan ( boost::string_ref parKey );
|
||||
|
||||
private:
|
||||
using RedisConnection = std::unique_ptr<redisContext, void(*)(redisContext*)>;
|
||||
|
|
|
@ -95,6 +95,22 @@ namespace redis {
|
|||
static const T& make_value ( const RedisReplyType* parItem );
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ScanSingleValuesInKey {
|
||||
typedef T value_type;
|
||||
|
||||
explicit ScanSingleValuesInKey ( boost::string_ref parScanTarget ) : m_scan_target(parScanTarget) {}
|
||||
|
||||
static constexpr const char* command ( void ) { return "SSCAN"; }
|
||||
static constexpr const std::size_t step = 1;
|
||||
|
||||
static const T& make_value ( const RedisReplyType* parItem );
|
||||
boost::string_ref scan_target ( void ) const { return m_scan_target; }
|
||||
|
||||
private:
|
||||
boost::string_ref m_scan_target;
|
||||
};
|
||||
|
||||
template <typename P, typename A=decltype(P().first), typename B=decltype(P().second)>
|
||||
struct ScanPairs {
|
||||
typedef P value_type;
|
||||
|
@ -105,7 +121,7 @@ namespace redis {
|
|||
static constexpr const std::size_t step = 2;
|
||||
|
||||
static value_type make_value ( const RedisReplyType* parItem );
|
||||
boost::string_ref scan_target ( void );
|
||||
boost::string_ref scan_target ( void ) const { return m_scan_target; }
|
||||
|
||||
private:
|
||||
boost::string_ref m_scan_target;
|
||||
|
|
|
@ -147,14 +147,15 @@ namespace redis {
|
|||
return get<T>(*parItem);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto ScanSingleValuesInKey<T>::make_value (const RedisReplyType* parItem) -> const value_type& {
|
||||
assert(parItem);
|
||||
return get<T>(*parItem);
|
||||
}
|
||||
|
||||
template <typename P, typename A, typename B>
|
||||
auto ScanPairs<P, A, B>::make_value (const RedisReplyType* parItem) -> value_type {
|
||||
assert(parItem);
|
||||
return value_type(get<A>(parItem[0]), get<B>(parItem[1]));
|
||||
}
|
||||
|
||||
template <typename P, typename A, typename B>
|
||||
boost::string_ref ScanPairs<P, A, B>::scan_target() {
|
||||
return m_scan_target;
|
||||
}
|
||||
} //namespace redis
|
||||
|
|
Loading…
Add table
Reference in a new issue