0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Redisを5分間だけ触ってみた

Last updated at Posted at 2020-01-21

Redis

前から気になる存在だったので5分だけ触ってみた。思っていたよりもあっけなかった。

                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 12730
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                 

Redisの基礎知識

  • KVS
  • インメモリ
  • デフォルトで16個のデータベースを持っていて、それぞれ0~15のindexが割り当てられている

Redisサーバ立ち上げ

$ redis-server /usr/local/etc/redis.conf

Redisクライアント立ち上げ

# -nでデータベースの番号指定
$ redis-cli -n 1

あるいは$redis-cliでredisコンソールに入りSELECT 1でも良い。

Redisでpub/sub

# あるターミナルのタブにてsubscribe
$ redis-cli
127.0.0.1:6379> subscribe my_channel
1) "subscribe"
2) "my_channel"
3) (integer) 1
1) "message"       # 受け取った
2) "my_channel"    # 受け取った
3) "hello"       # 受け取った

# 別のタブにてpublish
$ redis-cli
127.0.0.1:6379> publish my_channel 'hello'
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?