「Ruby」- 访问Redis服务

  CREATED BY JENKINSBOT

内容简介

本文将介绍如何使用Ruby连接Redis服务、集群等等。

安装类库

#!/bin/sh

gem install redis

连接集群

require "redis"

# Nodes can be passed to the client as an array of connection URLs.
nodes = (7000..7005).map { |port| "redis://127.0.0.1:#{port}" }
redis = Redis.new(cluster: nodes)

redis.set "foo" 7

redis.get "foo"

参考文献

GitHub/redis/redis-rb