57
36

More than 3 years have passed since last update.

MacにRedisをインストールする

Last updated at Posted at 2018-06-06

Redisをインストールする

インストールにはhomebrewを使う

$ brew install redis
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/cask, homebrew/core).
==> Updated Formulae
amazon-ecs-cli            docker-swarm              firebase-cli              fuse-emulator             libspectrum               libxmlsec1                ohcount                   ppsspp                    telegraf                  traefik                   wolfssl

==> Downloading https://homebrew.bintray.com/bottles/redis-4.0.9.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring redis-4.0.9.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.9: 13 files, 2.8MB

Redisを起動する

redis-serverコマンドで起動する

$ redis-server
4729:C 06 Jun 11:20:49.472 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
4729:C 06 Jun 11:20:49.472 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=4729, just started
4729:C 06 Jun 11:20:49.472 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
4729:M 06 Jun 11:20:49.473 * Increased maximum number of open files to 10032 (it was originally set to 4864).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 4.0.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 4729
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

4729:M 06 Jun 11:20:49.474 # Server initialized
4729:M 06 Jun 11:20:49.474 * Ready to accept connections

Redisに接続する

redis-cliコマンドで接続する

$ redis-cli
127.0.0.1:6379>

データの登録と取得と削除

ちなみに、上のURLでredis-cliが直接試せる!

$ redis-cli
127.0.0.1:6379> set Key Value
OK
127.0.0.1:6379> get Key
"Value"
127.0.0.1:6379> del Key
(integer) 1
127.0.0.1:6379> get Key
(nil)
127.0.0.1:6379> Keys *
(empty list or set)

クエリを監視する

redis-cli
127.0.0.1:6379> monitor
OK
1528253210.741621 [0 127.0.0.1:50277] "COMMAND"
1528253218.106875 [0 127.0.0.1:50277] "Keys" "*"
.
.
.

クエリの監視結果をファイルに保存する

redis-cli -h `host` -p `port` -a `auth` monitor > monitor.log

redis-cliを終了する

127.0.0.1:6379> quit

redis-serverを停止する

redis-serverが起動しているコンソールでCtrl-C

^C6707:signal-handler (1528253381) Received SIGINT scheduling shutdown...
6707:M 06 Jun 11:49:41.134 # User requested shutdown...
6707:M 06 Jun 11:49:41.134 * Saving the final RDB snapshot before exiting.
6707:M 06 Jun 11:49:41.136 * DB saved on disk
6707:M 06 Jun 11:49:41.136 # Redis is now ready to exit, bye bye...
57
36
0

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
57
36