Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c53f12d

Browse filesBrowse files
theidexistedappkins
authored andcommitted
Make eval api simpler (#29)
Looks good, `DEPRECATED` should give people time to adjust to the new API. Thanks for the contribution.
1 parent f7e82e1 commit c53f12d
Copy full SHA for c53f12d

File tree

3 files changed

+63
-6
lines changed
Filter options

3 files changed

+63
-6
lines changed

‎includes/cpp_redis/core/client.hpp

Copy file name to clipboardExpand all lines: includes/cpp_redis/core/client.hpp
+17-4Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <cpp_redis/misc/logger.hpp>
4040
#include <cpp_redis/network/redis_connection.hpp>
4141
#include <cpp_redis/network/tcp_client_iface.hpp>
42+
#include <cpp_redis/misc/deprecated.hpp>
4243

4344
namespace cpp_redis {
4445

@@ -779,16 +780,28 @@ namespace cpp_redis {
779780

780781
std::future<reply> echo(const std::string &msg);
781782

782-
client &eval(const std::string &script, int numkeys, const std::vector<std::string> &keys,
783+
client &eval(const std::string &script, const std::vector<std::string> &keys,
783784
const std::vector<std::string> &args, const reply_callback_t &reply_callback);
784785

785-
std::future<reply> eval(const std::string &script, int numkeys, const std::vector<std::string> &keys,
786+
DEPRECATED client &eval(const std::string &script, int numkeys, const std::vector<std::string> &keys,
787+
const std::vector<std::string> &args, const reply_callback_t &reply_callback);
788+
789+
std::future<reply> eval(const std::string &script, const std::vector<std::string> &keys,
790+
const std::vector<std::string> &args);
791+
792+
DEPRECATED std::future<reply> eval(const std::string &script, int numkeys, const std::vector<std::string> &keys,
786793
const std::vector<std::string> &args);
787794

788-
client &evalsha(const std::string &sha1, int numkeys, const std::vector<std::string> &keys,
795+
client &evalsha(const std::string &sha1, const std::vector<std::string> &keys,
789796
const std::vector<std::string> &args, const reply_callback_t &reply_callback);
790797

791-
std::future<reply> evalsha(const std::string &sha1, int numkeys, const std::vector<std::string> &keys,
798+
DEPRECATED client &evalsha(const std::string &sha1, int numkeys, const std::vector<std::string> &keys,
799+
const std::vector<std::string> &args, const reply_callback_t &reply_callback);
800+
801+
std::future<reply> evalsha(const std::string &sha1, const std::vector<std::string> &keys,
802+
const std::vector<std::string> &args);
803+
804+
DEPRECATED std::future<reply> evalsha(const std::string &sha1, int numkeys, const std::vector<std::string> &keys,
792805
const std::vector<std::string> &args);
793806

794807
client &exec(const reply_callback_t &reply_callback);
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#if defined(__GNUC__) || defined(__clang__)
4+
#define DEPRECATED __attribute__((deprecated))
5+
#elif defined(_MSC_VER)
6+
#define DEPRECATED __declspec(deprecated)
7+
#else
8+
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
9+
#define DEPRECATED
10+
#endif

‎sources/core/client.cpp

Copy file name to clipboardExpand all lines: sources/core/client.cpp
+36-2Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,16 @@ namespace cpp_redis {
10031003
return *this;
10041004
}
10051005

1006+
client &
1007+
client::eval(const std::string &script, const std::vector<std::string> &keys,
1008+
const std::vector<std::string> &args, const reply_callback_t &reply_callback) {
1009+
std::vector<std::string> cmd = {"EVAL", script, std::to_string(keys.size())};
1010+
cmd.insert(cmd.end(), keys.begin(), keys.end());
1011+
cmd.insert(cmd.end(), args.begin(), args.end());
1012+
send(cmd, reply_callback);
1013+
return *this;
1014+
}
1015+
10061016
client &
10071017
client::evalsha(const std::string &sha1, int numkeys, const std::vector<std::string> &keys,
10081018
const std::vector<std::string> &args, const reply_callback_t &reply_callback) {
@@ -1013,6 +1023,16 @@ namespace cpp_redis {
10131023
return *this;
10141024
}
10151025

1026+
client &
1027+
client::evalsha(const std::string &sha1, const std::vector<std::string> &keys,
1028+
const std::vector<std::string> &args, const reply_callback_t &reply_callback) {
1029+
std::vector<std::string> cmd = {"EVALSHA", sha1, std::to_string(keys.size())};
1030+
cmd.insert(cmd.end(), keys.begin(), keys.end());
1031+
cmd.insert(cmd.end(), args.begin(), args.end());
1032+
send(cmd, reply_callback);
1033+
return *this;
1034+
}
1035+
10161036
client &
10171037
client::exec(const reply_callback_t &reply_callback) {
10181038
send({"EXEC"}, reply_callback);
@@ -3671,13 +3691,27 @@ namespace cpp_redis {
36713691
std::future<reply>
36723692
client::eval(const std::string &script, int numkeys, const std::vector<std::string> &keys,
36733693
const std::vector<std::string> &args) {
3674-
return exec_cmd([=](const reply_callback_t &cb) -> client & { return eval(script, numkeys, keys, args, cb); });
3694+
(void) numkeys;
3695+
return exec_cmd([=](const reply_callback_t &cb) -> client & { return eval(script, keys, args, cb); });
3696+
}
3697+
3698+
std::future<reply>
3699+
client::eval(const std::string &script, const std::vector<std::string> &keys,
3700+
const std::vector<std::string> &args) {
3701+
return exec_cmd([=](const reply_callback_t &cb) -> client & { return eval(script, keys, args, cb); });
3702+
}
3703+
3704+
std::future<reply>
3705+
client::evalsha(const std::string &sha1, const std::vector<std::string> &keys,
3706+
const std::vector<std::string> &args) {
3707+
return exec_cmd([=](const reply_callback_t &cb) -> client & { return evalsha(sha1, keys, args, cb); });
36753708
}
36763709

36773710
std::future<reply>
36783711
client::evalsha(const std::string &sha1, int numkeys, const std::vector<std::string> &keys,
36793712
const std::vector<std::string> &args) {
3680-
return exec_cmd([=](const reply_callback_t &cb) -> client & { return evalsha(sha1, numkeys, keys, args, cb); });
3713+
(void) numkeys;
3714+
return exec_cmd([=](const reply_callback_t &cb) -> client & { return evalsha(sha1, keys, args, cb); });
36813715
}
36823716

36833717
std::future<reply>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.