Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Cloud9でredisのリコメンドエンジン「Recommendify」を導入する

More than 3 years have passed since last update.

Recommendifyって何ができるの?

RecommendifyとはAmazonのようなリコメンド機能を実装するライブラリ。
RubyとRedisベースのリコメンドエンジンで、ユーザーの購入ログから商品などの関連度を算出してくれる。
複雑なリコメンドエンジンが多い中簡単にリコメンド機能を実装することができる。

Linuxbrew

ローカル開発環境の場合はHomebrewでredisやらをインストールしていけばいいのだがcloud9にはHomebrewは導入できないので代わりにLinuxbrewを入れる。

インストール

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/linuxbrew/go/install)"
==> This script will install:
/home/ubuntu/.linuxbrew/bin/brew
/home/ubuntu/.linuxbrew/Library/...
/home/ubuntu/.linuxbrew/share/man/man1/brew.1

Press RETURN to continue or any other key to abort

となるので適当なキーを押す。

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/linuxbrew/go/install)"
==> This script will install:
/home/ubuntu/.linuxbrew/bin/brew
/home/ubuntu/.linuxbrew/Library/...
/home/ubuntu/.linuxbrew/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
remote: Counting objects: 353405, done.
remote: Total 353405 (delta 0), reused 0 (delta 0), pack-reused 353405
Receiving objects: 100% (353405/353405), 67.67 MiB | 13.29 MiB/s, done.
Resolving deltas: 100% (267220/267220), done.
From https://github.com/Homebrew/linuxbrew
 * [new branch]      master     -> origin/master
HEAD is now at eec5059 Merge branch homebrew/master into linuxbrew/master
Warning: /home/ubuntu/.linuxbrew/bin is not in your PATH.
==> Installation successful!
==> Next steps
Install the Linuxbrew dependencies:

Debian, Ubuntu, etc.:
  `sudo apt-get install build-essential`

Fedora, Red Hat, CentOS, etc.:
  `sudo yum groupinstall 'Development Tools'`

See http://brew.sh/linuxbrew/#dependencies for more information.

Run `brew doctor` before you install anything
Run `brew help` to get started

と出てきたらbrewdoctorをやってみよう。パスが通っていないはず。

$ brew doctor
bash: brew: command not found

パスを通す

$ export PATH=$PATH:/home/ubuntu/.linuxbrew/bin
$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: Setting LD_* vars can break dynamic linking.
Set variables:
    LD_LIBRARY_PATH: ~/.c9/local/lib

warningは今回は問題ないので無視してOK

Redisの導入

gemでも配布されていますが、bundleではなくbrewから入れる必要があります。

インストール

$ brew install redis
==> Downloading http://download.redis.io/releases/redis-3.2.1.tar.gz
######################################################################## 100.0%
==> make install PREFIX=/home/ubuntu/.linuxbrew/Cellar/redis/3.2.1 CC=/usr/bin/gcc-4.8
/home/ubuntu/.linuxbrew/Cellar/redis/3.2.1: 9 files, 11.4M, built in 57 seconds

サーバー起動

$ redis-server

シャットダウン

別ターミナルから行う

$ redis-cli shutdown

hiredisの導入

次はhiredisのインストール。Recommendifyを入れるのに必要なライブラリなので必ず入れましょう。

$ brew install hiredis
==> Downloading https://github.com/redis/hiredis/archive/v0.13.3.tar.gz
==> Downloading from https://codeload.github.com/redis/hiredis/tar.gz/v0.13.3
######################################################################## 100.0%
==> make install PREFIX=/home/ubuntu/.linuxbrew/Cellar/hiredis/0.13.3
/home/ubuntu/.linuxbrew/Cellar/hiredis/0.13.3: 30 files, 548.4K, built in 5 seconds

Recommendifyの導入

Gemfileを作成

Gemfile
source 'https://rubygems.org'

gem 'sinatra'
gem 'sinatra-contrib'
gem 'activerecord'
gem 'sinatra-activerecord'
gem 'recommendify', git: "https://github.com/danmorin/recommendify.git", branch: "native"

Recommendifyのインストール

$ bundle
bash: bundle: command not found
$ gem install bundler
Fetching: bundler-1.12.5.gem (100%)      Fetching: bundler-1.12.5.gem
Successfully installed bundler-1.12.5
1 gem installed
$ bundle
(省略)

参考ページ

cloud9上のlinuxにLinuxbrewを入れる

cultn0923
SFCの大学2年です。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away