工作中很多项目涉及到Redis,仅做一些记录。
官网说明:Redis is an open source, BSD licensed, advanced key-value cache and store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs.。
[root@rhel63 opt]# ls -l redis-2.8.19.tar.gz
-rw-r--r-- 1 yong yong 1254857 Apr 1 11:23 redis-2.8.19.tar.gz
[root@rhel63 opt]# tar -zxvf redis-2.8.19.tar.gz
[root@rhel63 opt]# cd redis-2.8.19
[root@rhel63 redis-2.8.19]# ls
00-RELEASENOTES CONTRIBUTING deps Makefile README runtest sentinel.conf tests
BUGS COPYING INSTALL MANIFESTO redis.conf runtest-sentinel src utils
查看README,最简单的方式安装
[root@rhel63 redis-2.8.19]# make
[root@rhel63 redis-2.8.19]# make install
启动redis服务,默认端口是6379
[root@rhel63 redis-2.8.19]# cd src/
[root@rhel63 src]# ./redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit
[root@rhel63 src]# ./redis-server
[5894] 01 Apr 11:48:39.987 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
[5894] 01 Apr 11:48:39.991 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.19 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 5894
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[5894] 01 Apr 11:48:39.999 # Server started, Redis version 2.8.19
[5894] 01 Apr 11:48:39.999 # 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.
[5894] 01 Apr 11:48:39.999 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[5894] 01 Apr 11:48:40.000 * The server is now ready to accept connections on port 6379
打开另外一个终端
[root@rhel63 src]# ./redis-cli
127.0.0.1:6379> set hello world
OK
127.0.0.1:6379> get hello
"world"
127.0.0.1:6379> del hello
(integer) 1
127.0.0.1:6379> get hello
(nil)
127.0.0.1:6379> set hello hello redis
(error) ERR syntax error
127.0.0.1:6379> set hello "hello redis"
OK
127.0.0.1:6379> get hello
"hello redis"
127.0.0.1:6379> set hello 'hello world'
OK
127.0.0.1:6379> get hello
"hello world"
ctrl+c 退出redis,从下面信息看到中断redis后redis对内存数据做了持久化
^C[5894 | signal handler] (1427860456) Received SIGINT scheduling shutdown...
[5894] 01 Apr 11:54:16.815 # User requested shutdown...
[5894] 01 Apr 11:54:16.815 * Saving the final RDB snapshot before exiting.
[5894] 01 Apr 11:54:16.840 * DB saved on disk
[5894] 01 Apr 11:54:16.840 # Redis is now ready to exit, bye bye...
后台运行redis
[root@rhel63 src]# nohup ./redis-server &
既然是数据库,测试是远程连接,打开另外一台主机
[root@rhel63 redis-2.8.19]# make
[root@rhel63 redis-2.8.19]# cd src/
[root@rhel63 src]# ./redis-cli -h 192.168.171.130 -p 6379
192.168.171.130:6379> get hello
"hello world"
hello记录果然还存在,
使用shutdown来停止redis服务