Redis ( 1 ) ~ セットアップ編 ~

September 10, 2017

Redis のインストール

$ sudo apt-get install make gcc python-dev
$ wget http://redis.googlecode.com/files/redis-3.2.4.tar.gz
$ tar -xzf redis-3.2.4.tar.gz 
$ cd redis-3.2.4/
$ make
$ sudo make install

$ redis-server redis.conf 
13640:M 10 Sep 06:31:46.957 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
13640:M 10 Sep 06:31:46.957 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
13640:M 10 Sep 06:31:46.957 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.4 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 13640
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

13640:M 10 Sep 06:31:46.958 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
13640:M 10 Sep 06:31:46.958 # Server started, Redis version 3.2.4
13640:M 10 Sep 06:31:46.958 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
13640:M 10 Sep 06:31:46.958 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
13640:M 10 Sep 06:31:46.958 * The server is now ready to accept connections on port 6379

Redis クライアントライブラリのインストール

# For php5
$ sudo apt-get install php5-dev
$ git clone git://github.com/nicolasff/phpredis.git
$ cd phpredis/
$ phpize5
$ ./configure
$ make
$ sudo make install
Installing shared extensions:     /usr/lib/php5/20121212/

# phpredis
sudo apt-get install php5-redis
# For Python
$ sudo apt-get -y install python-redis

redis-cli から操作してみる

$ redis-cli 
127.0.0.1:6379> set hello world # hello キーに world 値を格納
OK
127.0.0.1:6379> get hello # hello キーの値を取得
"world"
127.0.0.1:6379> del hello # キーバリューペアを削除
(integer) 1
127.0.0.1:6379> get hello 
(nil)

 © 2023, Dealing with Ambiguity