
Show HN: Cpp_Redis – C++11 Lightweight Redis client - cylix
https://github.com/Cylix/cpp_redis
======
albeva
Neat, but horrid naming for everything. Why does namespace need explicit
"cpp_" prefix? Why do classes inside "cpp_redis" namespace still have "redis_"
prefix? I would prefer simple "redis::client" so much nicer than
"cpp_redis::redis_client"

~~~
clishem

        namespace redis = cpp_redis;
    

there you go.

~~~
adgasf
A quick fix, but having many of these can make code much harder to read since
you will need to trace through the various aliases to find the actual
implementation.

------
hans0l074
A few years ago, I dabbled with the idea of building a "shared clipboard"
application across platforms and decided to use Redis - esply the pub/sub
mechanism - for this. I ended up discovering and using hiredis[0] (which I can
see now was co-authored by antirez as well). I'm curious to know if hiredis
can be used from C++ 11 as well.

[0] [https://github.com/redis/hiredis](https://github.com/redis/hiredis)

~~~
pjmlp
As arjo129 says, there is nothing preventing you from using hiredis, provided
they don't make use of the few cases where C language features and C++ are no
longer compatible, e.g. VLAs or structure initializers.

However, given it is a C API you will get the usual C unsafe code, instead of
C++'s improvements regarding type safety.

~~~
jjnoakes
> provided they don't make use of the few cases where C language features and
> C++ are no longer compatible, e.g. VLAs or structure initializers

Wouldn't one compile hiredis in C, their app in C++, and link the two
together?

In general compiling C code with a C++ compiler isn't the path of least
resistance.

~~~
pjmlp
Depends how C++ compatible are the headers, as they can't make use of C99 or
C11 features that aren't part of ANSI C++17.

~~~
jjnoakes
True, although most C libraries ought to use those features in the
implementation files and not the headers if they want to be used widely.

And even if some things leak into the headers they might be accepted by
compiler extensions.

But yes, in general if a c library's headers are hostile to cross-language
usage then using it from c++ won't be trivial.

------
asveikau
Looks like a learning project for someone relatively new to C++.

I suggest using git tags instead of putting a version number in every commit
message.

Have you looked into epoll or kqueue or even poll? Or for your windows
backend, WSAEventSelect/WaitForMultipleObjects or IOCP... Trying to get all
these disparate ways of doing async sockets to use a consistent wrapper
interface is an interesting challenge.

~~~
cylix
Hi,

I do use git tags but I also include version numbers in my commit messages so
that I can easily determine in which version a given commit was published. I
find it pretty useful. I know some people prefer to create a dev branch, then
squash merge, but sometimes you got multiple features and I feel it is more
convenient to separate them into multiple commits that will belongs to the
same release. Do you have some other suggestions, I would be interested :)

Concerning epoll/poll, the networking part was first based on it. However, the
poll implementation on windows is buggy and thus it is more advised to use
select on windows apparently... So to keep consistency between unix and
windows versions, I decided to switch back to select for both platform for
now. I'm planning to switch back to poll for unix and look at WSAEventSelect.

I also looked at IOCP and it is really interesting. However, it is pretty hard
to implement a portable library that uses select/poll under unix but IOCP on
windows as the implementation is pretty different. There are some ways, but
the way I designed the networking part does not make it possible without
changing completely the design on one platform

~~~
asveikau
Running `git describe` will give you the nearest tag. gitk will also show you
the tag in a manner similar to how it displays a branch head.

~~~
jhasse
Btw: gitg is a slightly more modern looking gitk alternative :)

(it also shows tags similar to branch heads)

~~~
asveikau
On the other hand, gitk is light, simple, cross-platform, and works.

~~~
jhasse
You're right, gitg doesn't work on macOS. But since I'm only using Windows and
Linux it works for me :)

------
dvirsky
Nice. Would you consider a mechanism for injecting the client with extra
commands for redis modules? As far as I can tell it's possible to run generic
commands with the client, but it would be a nice touch to add more commands to
it.

------
faithful09234
My experience over the last five years pertaining to software requirements
have been:

Does it require low latency? Yes -> use Clang environment. In this case, redis
usually doesn't fit the bill within the stack. I'm surprised for most other
use cases, people are using C++, where Ruby/Java can provide a solid
programming abstraction (and fast development time). tl;dr I would be curious
of the use case of C++ and redis.

~~~
detaro
Redis is commonly used to share data/communicate between different subsystems,
potentially written in different languages.

------
10000101
Silly question, but if redis is written in c , couldn't c++ call redis'
interface directly. I'm aware it wouldn't be best practice and there would be
problems if redis' c code base was non-compliant with c++ standards? But is
this effectively a c++ wrapper ?

~~~
clishem
This is not a silly question. Yes, using the C library from C++ is certainly
possible. There would be nothing non-compliant about that, although you would
need to write code that is somewhat frowned upon when writing C++ (i.e. using
raw pointers all over the place). No, this is not a wrapper. It doesn't use
the C library to pass queries to redis.

~~~
10000101
Makes sense, thanks for clarifying clishem

------
keymone
made this couple years ago:
[https://gist.github.com/keymone/b89c23e3e43beb97eb94](https://gist.github.com/keymone/b89c23e3e43beb97eb94)
(tiny ruby redis client)

------
c4pt0r
[https://github.com/Cylix/tacopie](https://github.com/Cylix/tacopie) an
interesting network library.

~~~
c4pt0r
which is used in this project (Cpp_Redis)

------
gaius
Does this correctly handle Redis clustering? E.g. the "get it from this other
node" message? I don't see a handler for that in redis_client.cpp.

~~~
dvirsky
Looks like it doesn't, although it supports the cluster control API.

~~~
cylix
exactly, it only supports cluster control API for now

~~~
dvirsky
Why not go full cluster?

