mirror of
https://github.com/KingDuckZ/incredis
synced 2025-08-11 13:09:48 +00:00
Add set/get/flushdb/dbsize convenience methods.
This commit is contained in:
parent
68a73d3eb6
commit
20edb06241
5 changed files with 77 additions and 2 deletions
|
@ -82,6 +82,14 @@ namespace redis {
|
|||
//Script
|
||||
bool script_flush ( void );
|
||||
|
||||
//Misc
|
||||
bool flushdb ( void );
|
||||
RedisInt dbsize ( void );
|
||||
|
||||
//String
|
||||
opt_string get ( boost::string_ref parKey );
|
||||
bool set ( boost::string_ref parKey, boost::string_ref parField );
|
||||
|
||||
private:
|
||||
static opt_string_list reply_to_string_list ( const Reply& parReply );
|
||||
|
||||
|
|
|
@ -33,6 +33,12 @@ namespace redis {
|
|||
ZADD_None
|
||||
};
|
||||
|
||||
enum ADD_Mode {
|
||||
ADD_XX,
|
||||
ADD_NX,
|
||||
ADD_None
|
||||
};
|
||||
|
||||
IncRedisBatch ( void ) = delete;
|
||||
IncRedisBatch ( IncRedisBatch&& ) = default;
|
||||
IncRedisBatch ( const Batch& ) = delete;
|
||||
|
@ -50,6 +56,11 @@ namespace redis {
|
|||
template <typename... Args>
|
||||
IncRedisBatch& del ( Args&&... parArgs );
|
||||
|
||||
//String
|
||||
IncRedisBatch& set ( boost::string_ref parKey, boost::string_ref parField, ADD_Mode parMode );
|
||||
template <typename... Args>
|
||||
IncRedisBatch& set ( boost::string_ref parKey, boost::string_ref parField, ADD_Mode parMode, Args&&... parArgs );
|
||||
|
||||
//Hash
|
||||
IncRedisBatch& hget ( boost::string_ref parKey, boost::string_ref parField );
|
||||
template <typename... Args>
|
||||
|
@ -136,6 +147,24 @@ namespace redis {
|
|||
return *this;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
IncRedisBatch& IncRedisBatch::set (boost::string_ref parKey, boost::string_ref parField, ADD_Mode parMode, Args&&... parArgs) {
|
||||
using dhandy::bt::index_range;
|
||||
|
||||
switch(parMode) {
|
||||
case ADD_None:
|
||||
implem::run_conv_floats_to_strings(m_batch, index_range<0, sizeof...(Args)>(), "SET", parKey, parField, std::forward<Args>(parArgs)...);
|
||||
break;
|
||||
case ADD_NX:
|
||||
implem::run_conv_floats_to_strings(m_batch, index_range<0, sizeof...(Args)>(), "SET", parKey, parField, "NX", std::forward<Args>(parArgs)...);
|
||||
break;
|
||||
case ADD_XX:
|
||||
implem::run_conv_floats_to_strings(m_batch, index_range<0, sizeof...(Args)>(), "SET", parKey, parField, "XX", std::forward<Args>(parArgs)...);
|
||||
break;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
namespace implem {
|
||||
template <std::size_t IGNORE_COUNT, std::size_t IDX, typename T, bool STRINGIZE=(IDX>=IGNORE_COUNT) && ((IDX-IGNORE_COUNT)%2)==0>
|
||||
struct stringize_or_forward_impl {
|
||||
|
@ -144,7 +173,7 @@ namespace redis {
|
|||
};
|
||||
template <std::size_t IGNORE_COUNT, std::size_t IDX, typename T>
|
||||
struct stringize_or_forward_impl<IGNORE_COUNT, IDX, T, true> {
|
||||
static_assert(std::is_floating_point<T>::value, "Scores must be given as floating point values");
|
||||
static_assert(std::is_floating_point<T>::value, "Value must be given as floating point number");
|
||||
typedef std::string type;
|
||||
static std::string do_it ( T parT ) { return boost::lexical_cast<std::string>(parT); }
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue