@@ -1564,6 +1564,98 @@ client::smove(const std::string& source, const std::string& destination, const s
15641564 return *this ;
15651565}
15661566
1567+
1568+ client&
1569+ client::sort (const std::string& key, const reply_callback_t & reply_callback) {
1570+ send ({" SORT" , key}, reply_callback);
1571+ return *this ;
1572+ }
1573+
1574+ client&
1575+ client::sort (const std::string& key, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const reply_callback_t & reply_callback) {
1576+ return sort (key, " " , false , 0 , 0 , get_patterns, asc_order, alpha, " " , reply_callback);
1577+ }
1578+
1579+ client&
1580+ client::sort (const std::string& key, std::size_t offset, std::size_t count, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const reply_callback_t & reply_callback) {
1581+ return sort (key, " " , true , offset, count, get_patterns, asc_order, alpha, " " , reply_callback);
1582+ }
1583+
1584+ client&
1585+ client::sort (const std::string& key, const std::string& by_pattern, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const reply_callback_t & reply_callback) {
1586+ return sort (key, by_pattern, false , 0 , 0 , get_patterns, asc_order, alpha, " " , reply_callback);
1587+ }
1588+
1589+ client&
1590+ client::sort (const std::string& key, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const std::string& store_dest, const reply_callback_t & reply_callback) {
1591+ return sort (key, " " , false , 0 , 0 , get_patterns, asc_order, alpha, store_dest, reply_callback);
1592+ }
1593+
1594+ client&
1595+ client::sort (const std::string& key, std::size_t offset, std::size_t count, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const std::string& store_dest, const reply_callback_t & reply_callback) {
1596+ return sort (key, " " , true , offset, count, get_patterns, asc_order, alpha, store_dest, reply_callback);
1597+ }
1598+
1599+ client&
1600+ client::sort (const std::string& key, const std::string& by_pattern, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const std::string& store_dest, const reply_callback_t & reply_callback) {
1601+ return sort (key, by_pattern, false , 0 , 0 , get_patterns, asc_order, alpha, store_dest, reply_callback);
1602+ }
1603+
1604+ client&
1605+ client::sort (const std::string& key, const std::string& by_pattern, std::size_t offset, std::size_t count, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const reply_callback_t & reply_callback) {
1606+ return sort (key, by_pattern, true , offset, count, get_patterns, asc_order, alpha, " " , reply_callback);
1607+ }
1608+
1609+ client&
1610+ client::sort (const std::string& key, const std::string& by_pattern, std::size_t offset, std::size_t count, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const std::string& store_dest, const reply_callback_t & reply_callback) {
1611+ return sort (key, by_pattern, true , offset, count, get_patterns, asc_order, alpha, store_dest, reply_callback);
1612+ }
1613+
1614+ client&
1615+ client::sort (const std::string& key, const std::string& by_pattern, bool limit, std::size_t offset, std::size_t count, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const std::string& store_dest, const reply_callback_t & reply_callback) {
1616+ std::vector<std::string> cmd = {" SORT" , key};
1617+
1618+ // ! add by pattern (optional)
1619+ if (!by_pattern.empty ()) {
1620+ cmd.push_back (" BY" );
1621+ cmd.push_back (by_pattern);
1622+ }
1623+
1624+ // ! add limit (optional)
1625+ if (limit) {
1626+ cmd.push_back (" LIMIT" );
1627+ cmd.push_back (std::to_string (offset));
1628+ cmd.push_back (std::to_string (count));
1629+ }
1630+
1631+ // ! add get pattern (optional)
1632+ for (const auto & get_pattern : get_patterns) {
1633+ if (get_pattern.empty ()) {
1634+ continue ;
1635+ }
1636+
1637+ cmd.push_back (" GET" );
1638+ cmd.push_back (get_pattern);
1639+ }
1640+
1641+ // ! add order by (optional)
1642+ cmd.push_back (asc_order ? " ASC" : " DESC" );
1643+
1644+ // ! add alpha (optional)
1645+ if (alpha) {
1646+ cmd.push_back (" ALPHA" );
1647+ }
1648+
1649+ // ! add store dest (optional)
1650+ if (!store_dest.empty ()) {
1651+ cmd.push_back (" STORE" );
1652+ cmd.push_back (store_dest);
1653+ }
1654+
1655+ send (cmd, reply_callback);
1656+ return *this ;
1657+ }
1658+
15671659client&
15681660client::spop (const std::string& key, const reply_callback_t & reply_callback) {
15691661 send ({" SPOP" , key}, reply_callback);
@@ -2736,6 +2828,51 @@ client::smove(const std::string& src, const std::string& dst, const std::string&
27362828 return exec_cmd ([=](const reply_callback_t & cb) -> client& { return smove (src, dst, member, cb); });
27372829}
27382830
2831+ std::future<reply>
2832+ client::sort (const std::string& key) {
2833+ return exec_cmd ([=](const reply_callback_t & cb) -> client& { return sort (key, cb); });
2834+ }
2835+
2836+ std::future<reply>
2837+ client::sort (const std::string& key, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha) {
2838+ return exec_cmd ([=](const reply_callback_t & cb) -> client& { return sort (key, get_patterns, asc_order, alpha, cb); });
2839+ }
2840+
2841+ std::future<reply>
2842+ client::sort (const std::string& key, std::size_t offset, std::size_t count, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha) {
2843+ return exec_cmd ([=](const reply_callback_t & cb) -> client& { return sort (key, offset, count, get_patterns, asc_order, alpha, cb); });
2844+ }
2845+
2846+ std::future<reply>
2847+ client::sort (const std::string& key, const std::string& by_pattern, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha) {
2848+ return exec_cmd ([=](const reply_callback_t & cb) -> client& { return sort (key, by_pattern, get_patterns, asc_order, alpha, cb); });
2849+ }
2850+
2851+ std::future<reply>
2852+ client::sort (const std::string& key, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const std::string& store_dest) {
2853+ return exec_cmd ([=](const reply_callback_t & cb) -> client& { return sort (key, get_patterns, asc_order, alpha, store_dest, cb); });
2854+ }
2855+
2856+ std::future<reply>
2857+ client::sort (const std::string& key, std::size_t offset, std::size_t count, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const std::string& store_dest) {
2858+ return exec_cmd ([=](const reply_callback_t & cb) -> client& { return sort (key, offset, count, get_patterns, asc_order, alpha, store_dest, cb); });
2859+ }
2860+
2861+ std::future<reply>
2862+ client::sort (const std::string& key, const std::string& by_pattern, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const std::string& store_dest) {
2863+ return exec_cmd ([=](const reply_callback_t & cb) -> client& { return sort (key, by_pattern, get_patterns, asc_order, alpha, store_dest, cb); });
2864+ }
2865+
2866+ std::future<reply>
2867+ client::sort (const std::string& key, const std::string& by_pattern, std::size_t offset, std::size_t count, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha) {
2868+ return exec_cmd ([=](const reply_callback_t & cb) -> client& { return sort (key, by_pattern, offset, count, get_patterns, asc_order, alpha, cb); });
2869+ }
2870+
2871+ std::future<reply>
2872+ client::sort (const std::string& key, const std::string& by_pattern, std::size_t offset, std::size_t count, const std::vector<std::string>& get_patterns, bool asc_order, bool alpha, const std::string& store_dest) {
2873+ return exec_cmd ([=](const reply_callback_t & cb) -> client& { return sort (key, by_pattern, offset, count, get_patterns, asc_order, alpha, store_dest, cb); });
2874+ }
2875+
27392876std::future<reply>
27402877client::spop (const std::string& key) {
27412878 return exec_cmd ([=](const reply_callback_t & cb) -> client& { return spop (key, cb); });
0 commit comments