Ruby

Redis has an official Ruby client, redis-rb, and this is the client used in this section.

Installing it:

$ gem install redis

In this section, the Ruby code has comments that represent the result of the previous expression. It is recommended to run all of the code from this section in the interactive Ruby interpreter (irb in the command line).

The basic commands in Ruby

The interface of redis-rb is very close to how you interact with Redis through redis-cli:

require 'redis' @redis = Redis.new(:host => "127.0.0.1", :port => 6379) @redis.set "string:my_key", "Hello World" @redis.get "string:my_key" # => "Hello World" @redis.incr "string:counter" @redis.mget ["string:my_key", "string:counter"] # => ["Hello World", "1"] @redis.rpush "list:my_list", ...

Get Redis Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.