redis介紹、安裝、redis持久化、redis數據類型

一、redis介紹redis

 二、安裝
管網: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

vim /etc/redis.conf //修改以下配置
daemonize yes
logfile "/var/log/redis.log" 
dir /data/redis_data/
appendonly yes
mkdir /data/redis
啓動:redis-server /etc/redis.confapp

以及其它設置:spa

echo "
sysctl vm.overcommit_memory=1
echo never > /sys/kernel/mm/transparent_hugepage/enabled ">>/etc/rc.localserver

 

三、redis持久化blog

RDB:get

AOF:(推薦使用AOF)hash

四、redis數據類型it

 

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 (多個值)io

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"

相關文章
相關標籤/搜索