Describe the bug
I try to test code in the example markdown as :
#include <cpp_redis/cpp_redis>
#include <iostream>
#ifdef _WIN32
#include <Winsock2.h>
#endif /* _WIN32 */
int
main(void) {
#ifdef _WIN32
//! Windows netword DLL init
WORD version = MAKEWORD(2, 2);
WSADATA data;
if (WSAStartup(version, &data) != 0) {
std::cerr << "WSAStartup() failure" << std::endl;
return -1;
}
#endif /* _WIN32 */
//! Enable logging
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
cpp_redis::client client;
client.connect("127.0.0.1", 6379, [](const std::string& host, std::size_t port, cpp_redis::client::connect_state status) {
if (status == cpp_redis::client::connect_state::dropped) {
std::cout << "client disconnected from " << host << ":" << port << std::endl;
}
});
// same as client.send({ "SET", "hello", "42" }, ...)
client.set("hello", "42", [](cpp_redis::reply& reply) {
std::cout << "set hello 42: " << reply << std::endl;
// if (reply.is_string())
// do_something_with_string(reply.as_string())
});
// same as client.send({ "DECRBY", "hello", 12 }, ...)
client.decrby("hello", 12, [](cpp_redis::reply& reply) {
std::cout << "decrby hello 12: " << reply << std::endl;
// if (reply.is_integer())
// do_something_with_integer(reply.as_integer())
});
// same as client.send({ "GET", "hello" }, ...)
client.get("hello", [](cpp_redis::reply& reply) {
std::cout << "get hello: " << reply << std::endl;
// if (reply.is_string())
// do_something_with_string(reply.as_string())
});
// commands are pipelined and only sent when client.commit() is called
// client.commit();
// synchronous commit, no timeout
client.sync_commit();
// synchronous commit, timeout
// client.sync_commit(std::chrono::milliseconds(100));
#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */
return 0;
}
I follow the command line in
https://github.com/cpp-redis/cpp_redis/wiki/Mac-&-Linux-Install
to install cpp_redis
and use
gcc -lstdc++ -lcpp_redis -ltacopie --std=c++11 test_redis.cpp -o testredis
to compile the code.
But it come out a error :
bash-5.0# gcc -lstdc++ -lcpp_redis -ltacopie --std=c++11 test_redis.cpp -o testredis
test_redis.cpp: In function 'int main()':
test_redis.cpp:27:104: error: 'cpp_redis::client::connect_state' has not been declared
27 | client.connect("127.0.0.1", 6379, [](const std::string& host, std::size_t port, cpp_redis::client::connect_state status) {
| ^~~~~~~~~~~~~
test_redis.cpp: In lambda function:
test_redis.cpp:28:46: error: 'cpp_redis::client::connect_state' has not been declared
28 | if (status == cpp_redis::client::connect_state::dropped) {
| ^~~~~~~~~~~~~
test_redis.cpp: In function 'int main()':
test_redis.cpp:31:14: error: no matching function for call to 'cpp_redis::client::connect(const char [10], int, main()::<lambda(const string&, std::size_t, int)>)'
31 | });
| ^
In file included from /usr/local/include/cpp_redis/cpp_redis:30,
from test_redis.cpp:1:
/usr/local/include/cpp_redis/core/client.hpp:116:9: note: candidate: 'void cpp_redis::client::connect(const string&, std::size_t, const connect_callback_t&, uint32_t, int32_t, uint32_t)'
116 | void connect(
| ^~~~~~~
/usr/local/include/cpp_redis/core/client.hpp:119:32: note: no known conversion for argument 3 from 'main()::<lambda(const string&, std::size_t, int)>' to 'const connect_callback_t&' {aka 'const std::function<void(const std::__cxx11::basic_string<char>&, long unsigned int, cpp_redis::connect_state)>&'}
119 | const connect_callback_t &connect_callback = nullptr,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/cpp_redis/core/client.hpp:134:9: note: candidate: 'void cpp_redis::client::connect(const string&, const connect_callback_t&, uint32_t, int32_t, uint32_t)'
134 | void connect(
| ^~~~~~~
/usr/local/include/cpp_redis/core/client.hpp:136:32: note: no known conversion for argument 2 from 'int' to 'const connect_callback_t&' {aka 'const std::function<void(const std::__cxx11::basic_string<char>&, long unsigned int, cpp_redis::connect_state)>&'}
136 | const connect_callback_t &connect_callback = nullptr,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
To Reproduce
Steps to reproduce the behavior:
- follow https://github.com/cpp-redis/cpp_redis/wiki/Mac-&-Linux-Install to install cpp_redis
- copy code in https://github.com/cpp-redis/cpp_redis/wiki/Examples#redis-client to a file(test_redis.cpp)
- try gcc -lstdc++ -lcpp_redis -ltacopie --std=c++11 test_redis.cpp -o testredis to compile
Expected behavior
compile success with no error or warning.
Screenshots
all codes, steps and outputs have been shown above.
Desktop (please complete the following information):
- firecracker microVM
- uname -a : Linux dab7670245ef 4.15.0-91-generic #92-Ubuntu SMP Fri Feb 28 11:09:48 UTC 2020 x86_64 Linux
- alpine