阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS7下部署 Redis3

102次阅读
没有评论

共计 5199 个字符,预计需要花费 13 分钟才能阅读完成。

CentOS7 之 Redis3 学习笔记

1 Redis 官网:
http://www.redis.io/

2 Redis 的下载地址:
http://download.redis.io/releases/redis-3.0.7.tar.gz
这里我们下载的是 redis-3.0.7.tar.gz

3 Redis 的简介:
Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
这段话来源于 Redis 的官网,这个是不是最有说服力!?^_^

4 我们可以通过 SecureCRT 或 XShell 连接至 CentOS7 服务器,并进入到 /usr/local/tools/ 目录中:
cd cd /usr/local/tools/
如果没有此目录,则创建,这个目录主要用于存放我们下载的一些安装包:
mkdir -p /usr/local/tools/

5 下载 redis-3.0.7.tar.gz 源码:
wget http://download.redis.io/releases/redis-3.0.7.tar.gz
也可以点击官网的 http://download.redis.io/releases/redis-3.0.7.tar.gz 地址现在下载到本机,然后通过 SecureFXP 上传到 /usr/local/tools/ 目录;

6 将 redis-3.0.7.tar.gz 源码解压缩:
tar xzf redis-3.0.7.tar.gz

7 编译 Redis 源码:
 进入到 Redis 的根目录 redis-3.0.7 中:
cd redis-3.0.7
执行编译命令:
make

8 我们来启动一下 Redist 服务器吧:
src/redis-server
 shell 给我们如下反馈,则表明 redis 服务启动成功:
1206:C 04 May 05:48:48.344 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
 _._
 _.-“__ ”-._
 _.-“ `. `_. ”-._ Redis 3.0.7 (00000000/0) 64 bit
 .-“ .-“`. “`\/ _.,_ ”-._
 (‘ , .-` | `,) Running in standalone mode
 |`-._`-…-` __…-.“-._|’` _.-‘| Port: 6379
 | `-._ `._ / _.-‘ | PID: 1206
 `-._ `-._ `-./ _.-‘ _.-‘
 |`-._`-._ `-.__.-‘ _.-‘_.-‘|
 | `-._`-._ _.-‘_.-‘ | http://redis.io
 `-._ `-._`-.__.-‘_.-‘ _.-‘
 |`-._`-._ `-.__.-‘ _.-‘_.-‘|
 | `-._`-._ _.-‘_.-‘ |
 `-._ `-._`-.__.-‘_.-‘ _.-‘
 `-._ `-.__.-‘ _.-‘
 `-._ _.-‘
 `-.__.-‘

 1206:M 04 May 05:48:48.347 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
 1206:M 04 May 05:48:48.347 # Server started, Redis version 3.0.7
 1206:M 04 May 05:48:48.347 # 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.
 1206:M 04 May 05:48:48.347 # 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.
 1206:M 04 May 05:48:48.355 * DB loaded from disk: 0.008 seconds
 1206:M 04 May 05:48:48.355 * The server is now ready to accept connections on port 6379
说明:redis 的默认端口号为 6379,我们可以看到当前的 redis 的 PID 为 1206,处于单机运行状态;src 目录下的 redis-server 表示 redis 服务端命令;

9 只启动了 redis 的服务端并没有什么具体的意义,那我们开始启动 redis 的客户端,来体验一下 redis 的魅力所在:
src/redis-cli
 src 下的 redis-cli 表示 redis 启动客户端的命令;

10 由于 redis 是由 C 语言开发,我们看一下 redis 支持的数据类型都有哪些,
String(字符串)
APPEND
 BITCOUNT
 BITOP
 DECR
 DECRBY
 GET
 GETBIT
 GETRANGE
 GETSET
 INCR
 INCRBY
 INCRBYFLOAT
 MGET
 MSET
 MSETNX
 PSETEX
 SET
 SETBIT
 SETEX
 SETNX
 SETRANGE
 STRLEN
 Hash(哈希表)
HDEL
 HEXISTS
 HGET
 HGETALL
 HINCRBY
 HINCRBYFLOAT
 HKEYS
 HLEN
 HMGET
 HMSET
 HSET
 HSETNX
 HVALS
 HSCAN
 List(列表)
BLPOP
 BRPOP
 BRPOPLPUSH
 LINDEX
 LINSERT
 LLEN
 LPOP
 LPUSH
 LPUSHX
 LRANGE
 LREM
 LSET
 LTRIM
 RPOP
 RPOPLPUSH
 RPUSH
 RPUSHX
 Set(集合)
SADD
 SCARD
 SDIFF
 SDIFFSTORE
 SINTER
 SINTERSTORE
 SISMEMBER
 SMEMBERS
 SMOVE
 SPOP
 SRANDMEMBER
 SREM
 SUNION
 SUNIONSTORE
 SSCAN
 SortedSet(有序集合)
ZADD
 ZCARD
 ZCOUNT
 ZINCRBY
 ZRANGE
 ZRANGEBYSCORE
 ZRANK
 ZREM
 ZREMRANGEBYRANK
 ZREMRANGEBYSCORE
 ZREVRANGE
 ZREVRANGEBYSCORE
 ZREVRANK
 ZSCORE
 ZUNIONSTORE
 ZINTERSTORE
 ZSCAN

11 redis 文档的中文翻译网站:
http://doc.redisfans.com/
有不明白的或遗忘的可以来这里查看;

12 redis 的基本数据单位为 SDS(simple dynamic string),其是在 C 语言的 char[] 数组之上封装的,用于存储基本的数据;

13 set 与 get 字符串:
 我们向 redis 服务器插入一个字符串类型的数据:
127.0.0.1:6379> set name ‘idea’
 shell 反馈给我们的结果如下:
OK
我们查看一下刚刚插入到 redis 服务器的 key 为 name 的 value:
127.0.0.1:6379> get name
 shell 反馈给我们的结果如下:
“idea”

14 我们做一个自增序列:
14.1 设置一个 key 为 orderid 序列,给其初始值为 10000:
incrby orderid 10000
 14.2 逐次执行递增操作:
incr orderid
查看 shell 反馈给我们的结果,是不是 redis 在以 1 的步长间隔递增?

15 我们做一个列表操作:
15.1 向 List 中自左向右加入 5 个整数:
127.0.0.1:6379> lpush nums 10 20 30 40 50
 shell 反馈给我们的结果如下:
(integer) 5
 15.2 我们从右侧取值,执行 5 次下面的命令,并查看 shell 的反馈:
127.0.0.1:6379> rpop nums
 “10”
 127.0.0.1:6379>
 127.0.0.1:6379> rpop nums
 “20”
 127.0.0.1:6379> rpop nums
 “30”
 127.0.0.1:6379> rpop nums
 “40”
 127.0.0.1:6379> rpop nums
 “50”
 127.0.0.1:6379> rpop nums
 (nil)
 127.0.0.1:6379> rpop nums
 (nil)
当执行第 6 次的时候,取不到值了,这像不像数据结构中的“堆”?
15.3 我们从左侧取值,执行 5 次下面的命令,并查看 shell 的反馈:
127.0.0.1:6379> lpop nums
 “50”
 127.0.0.1:6379> lpop nums
 “40”
 127.0.0.1:6379> lpop nums
 “30”
 127.0.0.1:6379> lpop nums
 “20”
 127.0.0.1:6379> lpop nums
 “10”
 127.0.0.1:6379> lpop nums
 (nil)
当执行到第 6 次后,也是取不到值了,样子还是很像数据结构中的“堆”的嘛!

下面关于 Redis 的文章您也可能喜欢,不妨参考下:

Ubuntu 14.04 下 Redis 安装及简单测试 http://www.linuxidc.com/Linux/2014-05/101544.htm

Redis 主从复制基本配置 http://www.linuxidc.com/Linux/2015-03/115610.htm

Redis 集群明细文档 http://www.linuxidc.com/Linux/2013-09/90118.htm

Ubuntu 12.10 下安装 Redis(图文详解)+ Jedis 连接 Redis http://www.linuxidc.com/Linux/2013-06/85816.htm

Redis 系列 - 安装部署维护篇 http://www.linuxidc.com/Linux/2012-12/75627.htm

CentOS 6.3 安装 Redis http://www.linuxidc.com/Linux/2012-12/75314.htm

Redis 安装部署学习笔记 http://www.linuxidc.com/Linux/2014-07/104306.htm

Redis 配置文件 redis.conf 详解 http://www.linuxidc.com/Linux/2013-11/92524.htm

Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里

更多 CentOS 相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-06/132680.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-22发表,共计5199字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中