Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Instant Redis Optimization How-to

You're reading from  Instant Redis Optimization How-to

Product type Book
Published in May 2013
Publisher Packt
ISBN-13 9781782164807
Pages 56 pages
Edition 1st Edition
Languages
Author (1):
Arun Chinnachamy Arun Chinnachamy
Profile icon Arun Chinnachamy
Toc

Using languages and drivers (Simple)


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.

Tip

It is important to update the client libraries when we update the Redis server to get support for new commands and features.

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.

How to do it...

  1. You need to download the redis-rb client library from the official GitHub page (https://github.com/redis/redis-rb).

  2. Create a new Ruby script that will connect to the Redis server. The following code should make a connection to the server, assuming the server is running on the local machine at port 6379:

    require "redis"
    redis = Redis.new(:host => "127.0.0.1", :port => 6379)
    
  3. After connecting, we can execute the following commands:

    redis.set("redis", "rocks")
    redis.get('redis')
    
  4. Close the connection once done.

    redis.quit
    

There's more…

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.

Client Libraries

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)

https://github.com/redis/hiredis

PHP

Predis

https://github.com/nrk/predis

Ruby

redis-rb

https://github.com/redis/redis-rb

Perl

Redis

https://github.com/melo/perl-redis

Python

redis-py

https://github.com/andymccurdy/redis-py

Java

Jedis

https://github.com/xetorthio/jedis

Node.js

node_redis

https://github.com/mranney/node_redis

Objective-C

ObjCHiredis

https://github.com/lp/ObjCHiredis

C#

Booksleeve

http://code.google.com/p/booksleeve/

arrow left Previous Section
You have been reading a chapter from
Instant Redis Optimization How-to
Published in: May 2013 Publisher: Packt ISBN-13: 9781782164807
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}