This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -v | |
| mkdir hiredisxtmp | |
| cd hiredisxtmp | |
| git clone https://github.com/redis/hiredis --depth 1 | |
| cd hiredis | |
| make && make install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Run your own custom operations | |
| redisReply* customOp = hiredisx::op::command("PING"); | |
| std::string response = customOp->str; | |
| std::cout << "PING to the " << response << std::endl; | |
| freeReplyObject(customOp); | |
| // Customize your connection configurations | |
| hiredisx::options::host = "localhost"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add this header after including the hiredis and hiredisx libraries in your build. | |
| #include "hiredisx.hpp" | |
| // Make sure you can connect to the redis instance. | |
| bool validConnection = hiredisx::test::connect(); | |
| if (validConnection) { | |
| std::string ping = hiredisx::ping(); // PONG if valid. | |
| bool set = hiredisx::set("foo", "bar"); // True if set |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # In the build folder | |
| ./server | |
| # In a new tab | |
| curl http://localhost:3000 | |
| # In a browser, you can just go to http://localhost:3000 to see the text "Aloha". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string connection::prepareContent(string content) { | |
| return "HTTP/1.0 200 OK\r\nContent-Length: " + to_string(content.size()) + "\r\n\r\n" + content; | |
| } | |
| void connection::run(){ | |
| try { | |
| cout << "Pinged" << endl; | |
| asio::write(socket, asio::buffer(prepareContent("Aloha")), asio::transfer_all()); | |
| } catch(std::exception& e) { | |
| cout << "An error occurred: " << e.what() << endl; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| server::server( | |
| asio::io_service& io_service, int port) : io_service(io_service), | |
| acceptor(io_service, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port)), | |
| new_conn(connection::create(io_service) | |
| ) { | |
| acceptor.async_accept( | |
| new_conn->getSocket(), | |
| bind( | |
| &server::handle_accept, | |
| this, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class server : private noncopyable { | |
| public: | |
| server(asio::io_service& io_service, int port = 3000); | |
| private: | |
| void handle_accept(const system::error_code& e); | |
| asio::io_service& io_service; | |
| asio::ip::tcp::acceptor acceptor; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cmake_minimum_required(VERSION 2.6) | |
| PROJECT(BoostWeb) | |
| SET(Boost_USE_STATIC_LIBS ON) | |
| SET(Boost_USE_MULTITHREAD ON) | |
| FIND_PACKAGE(Boost REQUIRED COMPONENTS system thread regex) | |
| IF(Boost_FOUND) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Install boost and cmake for Mac OS via homebrew | |
| brew install boost | |
| brew install cmake | |
| # Install boost and cmake for Debian | |
| sudo apt-get install libboost-all-dev -y | |
| sudo apt-get install cmake -y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() { | |
| for (int index = 0; index < 10; index++) { | |
| cout << to_string(int) << endl; | |
| } | |
| return 0; | |
| } |