Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
set -v
mkdir hiredisxtmp
cd hiredisxtmp
git clone https://github.com/redis/hiredis --depth 1
cd hiredis
make && make install
// 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";
// 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
# 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".
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;
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,
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;
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)
# 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
#include <iostream>
using namespace std;
int main() {
for (int index = 0; index < 10; index++) {
cout << to_string(int) << endl;
}
return 0;
}