redis介绍、安装、redis持久化、redis数据类型
1、redis介绍
2、安装
管网:https://redis.io/
下载:wget -c http://download.redis.io/releases/redis-4.0.11.tar.gz
解压:tar -xvf redis-4.0.11.tar.gz
cd redis-4.0.11/
它没有configure 文件,直接make
make install
复制配制文件到etc下:cp redis.conf /etc/
修改配制文件:
vim /etc/redis.conf //修改如下配置
daemonize yes
logfile "/var/log/redis.log"
dir /data/redis_data/
appendonly yes
mkdir /data/redis
启动:redis-server /etc/redis.conf
以及其它设置:
echo "
sysctl vm.overcommit_memory=1
echo never > /sys/kernel/mm/transparent_hugepage/enabled ">>/etc/rc.local
3、redis持久化
RDB:
AOF:(推荐使用AOF)
4、redis数据类型
127.0.0.1:6379> set key "aaaa" (设置)
127.0.0.1:6379> get key (查看)
127.0.0.1:6379> mset key1 1 key2 a key3 cc (多个值)
127.0.0.1:6379> mget key1 key2 key3 (多个值)
127.0.0.1:6379> LPUSH list1 "abc" (创建列表,并赋值)
127.0.0.1:6379> LPUSH list1 "1 2 3"
127.0.0.1:6379> LPUSH list1 "aaa bbb“
127.0.0.1:6379> LRANGE list1 0 -1 (查看列表)
127.0.0.1:6379> LPOP list1 (取出列表中的某个值)
127.0.0.1:6379> SREM set1 c//删除元素
127.0.0.1:6379> SADD set2 a 2 b
127.0.0.1:6379> SINTER set1 set2 //交集
127.0.0.1:6379> SUNION set1 set2 //并集
127.0.0.1:6379> SDIFF set1 set2 //差集
127.0.0.1:6379> ZADD set3 12 abc
127.0.0.1:6379> ZADD set3 2 "cde 123"
127.0.0.1:6379> ZADD set3 24 "123-aaa"
127.0.0.1:6379> ZADD set3 4 "a123a"
127.0.0.1:6379> ZRANGE set3 0 -1
1) "cde 123"
2) "a123a"
3) "abc"
4) "123-aaa"
倒序 ZREVRANGE set3 0 -1
1) "123-aaa"
2) "abc"
3) "a123a"
4) "cde 123"
127.0.0.1:6379> hset hash1 name ccc
127.0.0.1:6379> hget hash1 name
127.0.0.1:6379> hset hash1 age 30
127.0.0.1:6379> hget hash1 age
127.0.0.1:6379> hgetall hash1
1) "name"
2) "aming"
3) "age"
4) "30"