LoginSignup
1
2

More than 3 years have passed since last update.

Redisの概要と導入方法

Last updated at Posted at 2018-10-09

Redisとは

keyとvalueの組み合わせでデータを保管できる小さいデータベースのようなもの。
軽量で高速なため、何かしらのデータをキャッシュしておくキャッシュサーバーとして利用されることが多い。

Redisの特徴

  • インメモリデータベース(速い)
  • データ永続化(定期的にディスクに書き出す)
  • データ構造サーバー(複雑なデータ型を扱うことができる)
  • Key-Value Store(キーと値の組み合わせで保存する)

Redisのデータ構造

  • String
  • List
  • Set
  • Sorted Set
  • Hash

公式サイト

Redis公式サイト
サイト上でコマンドを実行できるのがすごい。

インストール方法

HomeBrewを利用してインストールすると楽。

$ brew install redis

==> Downloading https://homebrew.bintray.com/bottles/redis-4.0.11.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring redis-4.0.11.high_sierra.bottle.tar.gz
==> Caveats
To have launchd start redis now and restart at login:
  brew services start redis
Or, if you don't want/need a background service you can just run:
  redis-server /usr/local/etc/redis.conf
==> Summary
🍺  /usr/local/Cellar/redis/4.0.11: 13 files, 2.8MB

Redisサーバーを立ち上げる

なんかAAが表示されたらredisサーバーが立ち上がってます。

$ redis-server

7436:C 30 Sep 00:13:30.747 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7436:C 30 Sep 00:13:30.748 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=7436, just started
7436:C 30 Sep 00:13:30.748 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
7436:M 30 Sep 00:13:30.749 * Increased maximum number of open files to 10032 (it was originally set to 256).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.11 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 7436
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

7436:M 30 Sep 00:13:30.751 # Server initialized
7436:M 30 Sep 00:13:30.751 * Ready to accept connections

終了方法は、Ctr+Cか、クライアントから終了コマンドshutdownを入力する。

クライアントの起動と終了

起動

$ redis-cli

終了

$ exit

データの保存場所

redis-serverを実行したパスに"dump.rdb"というファイルが作成されている。

1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2