永続化の機能があるインメモリデータベースです。高速処理用に部分的に使われるなどのケースが多いようです。
インストールして、サーバーを立ち上げます。
[vagrant@localhost redis]$ redis-server [14193] 12 Nov 04:58:10.521 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf [14193] 12 Nov 04:58:10.522 # You requested maxclients of 10000 requiring at least 10032 max file descriptors. [14193] 12 Nov 04:58:10.522 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted. [14193] 12 Nov 04:58:10.522 # Current maximum open files is 1024. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'. _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.8.12 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 14193 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [14193] 12 Nov 04:58:10.524 # Server started, Redis version 2.8.12 [14193] 12 Nov 04:58:10.525 # 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. [14193] 12 Nov 04:58:10.526 * The server is now ready to accept connections on port 6379
cliからのアクセス, exit, shutdouwn
[vagrant@localhost redis]$ redis-cli
データベースの選択
> select
データの保存
> bgsave
bgsaveでデータベースを保存すると、redis-serverを立ち上げたディレクトリに、dump.rdbが作成されます。
データの設定
127.0.0.1:6379> set name yamada OK 127.0.0.1:6379> get name "yamada" 127.0.0.1:6379> mset email yamada@gmail.com score 120 OK 127.0.0.1:6379> get name email score (error) ERR wrong number of arguments for 'get' command 127.0.0.1:6379> mget name email score 1) "yamada" 2) "yamada@gmail.com" 3) "120"
incr score
127.0.0.1:6379> incr score (integer) 121 127.0.0.1:6379> get score "121" 127.0.0.1:6379> decrby score 10 (integer) 111 127.0.0.1:6379> get score "111"
keyの操作
127.0.0.1:6379> keys * 1) "name" 2) "score" 3) "email" 127.0.0.1:6379> keys *m* 1) "name" 2) "email" 127.0.0.1:6379> exists score (integer) 1 127.0.0.1:6379> exists age (integer) 0 127.0.0.1:6379> set age 14 OK 127.0.0.1:6379> rename age nenrei OK 127.0.0.1:6379> keys * 1) "nenrei" 2) "email" 3) "score" 4) "name" 127.0.0.1:6379> del nenrei (integer) 1 127.0.0.1:6379> keys * 1) "email" 2) "score" 3) "name" 127.0.0.1:6379> set age 14 OK 127.0.0.1:6379> expire age 5 (integer) 1 127.0.0.1:6379> get age (nil)