Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。从2010年3月15日起,Redis的开发工作由VMware主持。从2013年5月开始,Redis的开发由Pivotal赞助。
redis 常用数据类型
String
Hash
list
Set
Sorted set
yum -y install gcc gcc-c++ #安装 http://www.redis.io tar xf redis-4.0.10.tar.gz cd redis-4.0.10 less README.md make MALLOC=jemalloc ##############make MALLOC=libc make PREFIX=/application/redis install [root@A-host redis-4.0.10]# ll /application/redis/bin/ 总用量 35500 -rwxr-xr-x. 1 root root 5599894 8月 14 00:37 redis-benchmark //性能测试工具 -rwxr-xr-x. 1 root root 8332085 8月 14 00:37 redis-check-aof //更新日志检查 -rwxr-xr-x. 1 root root 8332085 8月 14 00:37 redis-check-rdb -rwxr-xr-x. 1 root root 5740250 8月 14 00:37 redis-cli //客户端命令操作 lrwxrwxrwx. 1 root root 12 8月 14 00:37 redis-sentinel -> redis-server -rwxr-xr-x. 1 root root 8332085 8月 14 00:37 redis-server //启动程序
#配置并启动redis export PATH=/application/redis/bin/:$PATH vim /etc/profile . /etc/profile [root@A-host redis-4.0.10]# redis-server --help Usage: ./redis-server [/path/to/redis.conf] [options] ./redis-server - (read config from stdin) ./redis-server -v or --version ./redis-server -h or --help ./redis-server --test-memory <megabytes> Examples: ./redis-server (run the server with default conf) ./redis-server /etc/redis/6379.conf ./redis-server --port 7777 ./redis-server --port 7777 --slaveof 127.0.0.1 8888 ./redis-server /etc/myredis.conf --loglevel verbose Sentinel mode: ./redis-server /etc/sentinel.conf --sentinel [root@A-host redis-4.0.10]# mkdir /application/redis/conf [root@A-host redis-4.0.10]# cp redis.conf /application/redis/conf/ [root@A-host redis-4.0.10]# redis-server /application/redis/conf/redis.conf [root@A-host redis-4.0.10]# 3221:C 14 Aug 00:48:24.886 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 3221:C 14 Aug 00:48:24.886 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=3221, just started 3221:C 14 Aug 00:48:24.886 # Configuration loaded 3221:M 14 Aug 00:48:24.887 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 4.0.10 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 3221 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 3221:M 14 Aug 00:48:24.935 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 3221:M 14 Aug 00:48:24.935 # Server initialized 3221:M 14 Aug 00:48:24.935 # 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. 3221:M 14 Aug 00:48:24.944 # 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. 3221:M 14 Aug 00:48:24.944 * Ready to accept connections [root@A-host redis-4.0.10]# killall redis-server 3221:signal-handler (1534178967) Received SIGTERM scheduling shutdown... 3221:M 14 Aug 00:49:27.679 # User requested shutdown... 3221:M 14 Aug 00:49:27.680 * Saving the final RDB snapshot before exiting. 3221:M 14 Aug 00:49:27.708 * DB saved on disk 3221:M 14 Aug 00:49:27.708 * Removing the pid file. 3221:M 14 Aug 00:49:27.709 # Redis is now ready to exit, bye bye... [1]+ Done redis-server /application/redis/conf/redis.conf [root@A-host redis-4.0.10]# sysctl vm.overcommit_memory=1 [root@A-host redis-4.0.10]# redis-server /application/redis/conf/redis.conf & //启动
#关闭方法 [root@A-host redis-4.0.10]# redis-cli shutdown
#redis客户端帮助 [root@A-host redis-4.0.10]# redis-cli --help
#数据测试 连接方法1: [root@A-host redis-4.0.10]# redis-cli 127.0.0.1:6379> help get GET key summary: Get the value of a key since: 1.0.0 group: string 连接方法2: [root@A-host redis-4.0.10]# redis-cli -h 127.0.0.1 -p 6379 set qinzc lllltest OK [root@A-host redis-4.0.10]# redis-cli -h 127.0.0.1 -p 6379 get qinzc "lllltest" 连接方法3: telnet 127.0.0.1 6379 查看redis状态: redis-cli -h localhost -p 6379 info
1.连接
redis-cli -h 192.168.1.33 -p 6379
2.基本操作
#设置 set a 1 #查询 get a #自增 INCR #自增步长 INCRBY #自减 DECR #自减步长 DECRBY
#将哈希表 key 中的域 field 的值设为 value HSET key field value #返回哈希表 key 中给定域 field 的值 HGET key field #返回哈希表 key 中,所有的域和值。 HGETALL key #在线修改 > config get maxmemory 1) "maxmemory" 2) "500000000" > config set maxmemory 600000000 OK > config get maxmemory 1) "maxmemory" 2) "600000000"
主从同步配置
http://redisdoc.com/topic/replication.html
#配置(从服务器) #配置文件中增加以下的这一行就可以了: slaveof 192.168.1.1 6379 #另外一种方法是调用 SLAVEOF 命令, 输入主服务器的 IP 和端口, 然后同步就会开始: 127.0.0.1:6379> SLAVEOF 192.168.1.1 10086 OK info
从提升为主
slaveof NO ONE
redis集群
https://github.com/CodisLabs/codis/blob/release3.2/doc/tutorial_zh.md
停留在世界边缘,与之惜别