【redis使用系列】cento安装redis3.2.1和基本操作

简单介绍

官网介绍(最后更新于2019-02-01):
Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.
It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.
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安装与配置

解压、编译

wget http://download.redis.io/releases/redis-3.2.1.tar.gz
tar xvf redis-3.2.1.tar.gz
cd redis-3.2.1
make && make install
mkdir -p /usr/local/redis/bin
mkdir -p /usr/local/redis/etc
cp redis.conf /usr/local/redis/etc/
cp src/redis-server src/redis-cli src/redis-benchmark /usr/local/redis/bin/
cd /usr/local/redis/bin/

编辑配置文件

修改redis配置文件内容

vim  /usr/local/redis/etc/redis.conf
bind 192.168.128.199
logfile /var/log/redis/redis.log

加入到环境变量

echo “export PATH=$PATH:/usr/local/redis/bin/“ /etc/profile
source /etc/profile

启动

/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf

开始操作

[root@localhost bin]# redis-cli -h 192.168.128.199
192.168.128.199:6379> echo helloredis
"helloredis"

redis常用数据类型和操作命令

正如官网上提到的,redis支持多种数据类型:strings, hashes, lists, sets, sorted sets。命令总览:

string适用场景和命令

hash适用场景和命令

list适用场景和命令

list的特性适用于哪些先进先出、先进后出的排序。

set适用场景和命令

sorted sets适用场景和命令