GithubHelp home page GithubHelp logo

halybang / hirediscpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from petrohi/hiredispp

0.0 1.0 0.0 116 KB

C++ wrapper for hiredis C library - Remove boost - Using C++11

License: Boost Software License 1.0

C++ 100.00%

hirediscpp's Introduction

Hirediscpp is forked from Hiredispp with some changed:

* Work with C++11
* Remove all boost requirement
* Modify code to work with libevent
* I don't like exception, so I commented out some exception
* Add .pri and .pro file for easy to add to QT project
* Modify example to work with libevent

Just open hirediscpp.pro with Qt Creator then enjoy !

Introduction
------------

Hiredispp is a C++ wrapper around hiredis C library. Hiredis is powerful yet low level client interface for Redis server. Hiredispp aims at providing Redis client interface for standard C++ by leveraging hiredis implementation.

Connection
----------

Connection to Redis server is represented by hiredispp::Redis class with type safe implementations of Redis commands

	hiredispp::Redis r("localhost");
	r.set("foo", "bar");
	std::string s = r.get("foo");
	boost::int64_t i = r.incr("counter");
	
Reply
-----

Multi-bulk Redis reply is represented by hiredispp::Redis::Reply type

	hiredispp::Redis::Reply reply = r.keys("foo:*");
	std::vector<std::string> keys;
	reply.toVector(keys);	

Dynamic Commands
----------------

It is possible to issue dynamically created commands with hiredispp::Redis::Command class

	std::vector<std::string> keys;
	hiredispp::Redis::Command sunionstore("SUNIONSTORE");
	sunionstore << "result" << keys;
	r.execute(sunionstore);

Pipelining
----------

Redis pipelining is enabled by pair of begin/end calls in hiredispp::Redis

	for (...)
	{	
		r.beginSadd(key, member);
	}

	for (...)
	{
		boost::int64_t c = r.endCommand();ng
	}

Also it possible to pipeline dynamic commands by executing vector of hiredispp::Redis::Command objects

	std::vector<hiredispp::Redis::Command> commands;
	for (...)
	{	
		commands.push_back(hiredispp::Redis::Command("SADD") << key << member);
	}
	std::vector<hiredispp::Redis::Reply> replies;
	r.execute(commands, replies);

Exceptions
----------

All hiredis library error conditions are thrown as hiredispp::RedisException

	try
	{
		r.ping();
	}
	catch (const hiredispp::RedisException& e)
	{
		cerr << e.what();
	}

After disconnection it is possible to reuse existing hiredispp::Redis object, it will attempt to restore connection.

UNICODE support
---------------

hiredispp::Redis has corresponding hiredispp::wRedis template instance that supports std::wstring. UNICODE strings are UTF-8 encoded for Redis.

hirediscpp's People

Contributors

halybang avatar max1mbo avatar petrohi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.