All the major programming languages have support for Redis through their client libraries. Even if your language of preference does not have a client library to connect and use Redis, it is fairly easy to write a basic client of your own, as the Redis protocol is simple to implement. So, in this recipe, we will cover some clients worth mentioning for commonly used programming languages.
Let us see how to use client libraries to connect to Redis. As part of this recipe, we will see how we can use redis-rb to connect to Redis using Ruby.
require "redis" redis = Redis.new(:host => "127.0.0.1", :port => 6379)
redis.set("redis", "rocks") redis.get('redis')
redis.quit
You can find multiple libraries that provide almost similar functionalities; the complete list of libraries available for Redis can be found on the official Redis website (http://redis.io/clients). Here we were focusing on stable, active, recommended, and feature-complete libraries only. An official supported library is available only for C; all the libraries for other languages were written and are maintained by the community or external developers.
The following table has the recommended libraries for popular programming languages (which are stable enough to be used in production):
Languages |
Library Name |
Repository URL |
---|---|---|
C |
hiredis (Officially supported) | |
PHP |
Predis | |
Ruby |
redis-rb | |
Perl |
Redis | |
Python |
redis-py | |
Java |
Jedis | |
Node.js |
node_redis | |
Objective-C |
ObjCHiredis | |
C# |
Booksleeve |
18.190.156.93