CentOS7下部署 Redis3

CentOS7 之 Redis3 学习笔记

1 Redis 官网:

2 Redis 的下载地址:

这里我们下载的是 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
也可以点击官网的 地址现在下载到本机,然后通过 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
 `-._ `-._ `-./ _.-' _.-'
 |`-._`-._ `-.__.-' _.-'_.-'|
 | `-._`-._ _.-'_.-' |
 `-._ `-._`-.__.-'_.-' _.-'
 |`-._`-._ `-.__.-' _.-'_.-'|
 | `-._`-._ _.-'_.-' |
 `-._ `-._`-.__.-'_.-' _.-'
 `-._ `-.__.-' _.-'
 `-._ _.-'
 `-.__.-'

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 文档的中文翻译网站:

有不明白的或遗忘的可以来这里查看;

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/acb5108769d2e40031875d5c67a60943.html