Redis-初识
Redis简介:
利用C语言开发,开源的,支持网络交互的,基于键值对的高性能存储服务系统,经典使用场景包含:缓存、计数器、消息队列、排行榜、社交网络、实时系统
特性:
速度快
---数据存储在内存中,单线程运行,每秒可达10W次读写
持久化
---Redis中所有数据保存在内存中,对数据的更新将异步保存到磁盘。包含RDB和AOF两种持久化方式。
支持多种数据结构
---主要:String/Blobs/Bitmaps、Hash Table、LinedLists、Sets、Sorted Sets
---衍生:BitMaps:位图、HyperLoglog:超小内存唯一值计数、GEO:地理位置系列
支持多种编程语言:
---Java、Php、Python、Ruby、Node.js
功能丰富:
---包含发布订阅、Lua脚本、事务、pipeline
主从复制:
---主服务器及从服务器,服务器同步为高可用(Reids-Sentinel),分布式提供支持(Redis-Cluster)
Redis安装:基于CentOS7
单机版:
wget http://download.redis.io/releases/redis-3.0.7.tar.gz tar -xzf redis-3.0.7.tar.gz ln -s redis-3.0.7 redis make && make install 测试redis是否可以安脚本语言装make test
make可能出现的报错情况及处理:
1、如果报错need tcl 则需要安装TCL工具 wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/ cd /usr/local/tcl8.6.1/unix/ sudo ./configure sudo make sudo make install 再次重试make test 成功 2、若出现如下提示,则说明未安装gcc,使用命令安装gcc:yum install gcc root@localhost redis-2.8.17]# make cd src && make all make[1]: Entering directory `/root/redis-2.8.17/src‘ CC adlist.o /bin/sh: cc: command not found make[1]: *** [adlist.o] Error 127 make[1]: Leaving directory `/root/redis-2.8.17/src‘ make: *** [all] Error 2 3、若出现如下提示,则将make改为make MALLOC=libc,推测是因为编译库的问题。 [root@localhost redis-2.8.17]# make cd src && make all make[1]: Entering directory `/root/redis-2.8.17/src‘ CC adlist.o In file included from adlist.c:34: zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory zmalloc.h:55:2: error: #error "Newer version of jemalloc required" make[1]: *** [adlist.o] Error 1 make[1]: Leaving directory `/root/redis-2.8.17/src‘ make: *** [all] Error 2
Redis文件结构说明:
redis-server:Redis服务器 redis-cli:Redis命令行客户端 redis-benchmark:Redis性能测试工具 redis-check-aof:AOF文件修复工具 redis-check-dump:RDB文件检查工具 redis-sentinel:Sentinel服务器(2.8以后)
启动方法:
1、最简启动: redis-server 验证服务是否启动: ps -ef|grep redis netstat -antpl|grep redis redis -cli -h ip -p port ping 2、动态参数启动: redis-server --port 6379 3、配置文件启动: redis-server configPath 比较: 生产环境选择配置启动 单机多实例配置文件可以用端口区分开
客户端连接:
redis-cli -h ip地址 -p 6379
ping --验证是否连接成功 成功:PONG 错误:ERROR
常用配置:
daemonize: 是否以守护进程模式启动Redis(no|yes) 默认no
port:端口,默认6379
logfile:Redis系统日志
dir:Redis工作目录