redis-client
启动客户端
auth xxx
输入密码
1. 启动
a) 启动redis-server
redis-cli
b) 启动 /bin/systemctl start redis.service
c) service start redis
2. 后台运行
redis-server&3. :/requirepass
4. redis-server--help
redis-server myredis.conf
5. keys *6. 访问指定IP:端口的redis服务器
redis-cli-h ip -p 端口
redis-cli-h172.26.77.93-p63797. redis五大类型:string类型 hash listset zset
string 字符串
127.0.0.1:6379> set p 1
OK
127.0.0.1:6379> get p
"1"127.0.0.1:6379> type p
string127.0.0.1:6379> mset w 1 e 3 //批量赋值
OK
127.0.0.1:6379> mget w e //批量查询1) "1"2) "3"127.0.0.1:6379> incr o //递增1
(integer) 1127.0.0.1:6379> get o
"1"127.0.0.1:6379> incr o
(integer) 2127.0.0.1:6379> get o
"2"127.0.0.1:6379> incrby o 5 //增加5,这种方式只能用于增加整数
(integer) 7127.0.0.1:6379> incrbyfloat o 1.5
<!--增加小数-->"8.5"127.0.0.1:6379> set u 5
OK
127.0.0.1:6379> append u 5//字符串追加
(integer) 2127.0.0.1:6379> get u
"55"127.0.0.1:6379> set m 1234567
OK
127.0.0.1:6379> getrange m 0 -2//字符串切片"123456"
set 集合
127.0.0.1:6379> sadd r 123
(integer) 3127.0.0.1:6379> scard r
(integer) 3127.0.0.1:6379> smembers r
1) "1"2) "2"3) "3"127.0.0.1:6379> spop r //无序删除"3"127.0.0.1:6379>type r
set
sorted set有序集合
127.0.0.1:6379> zadd g 12 m2
<!--添加元素-->
(integer) 1
127.0.0.1:6379> zadd g 14 m3
(integer) 1
127.0.0.1:6379> zadd g 15 m3
(integer) 0
127.0.0.1:6379> zrange g 0 -1
1) "m2"
2) "m3"
127.0.0.1:6379> zadd g 19 m4
(integer) 1
127.0.0.1:6379> zadd g 20 m5
(integer) 1
127.0.0.1:6379> zrange
127.0.0.1:6379> zscore g m1
(nil)
127.0.0.1:6379> zscore g m2
"12"
127.0.0.1:6379> zrange g 0 -1
<!--排序-->
1) "m2"
2) "m3"
3) "m4"
4) "m5"
127.0.0.1:6379> zrevrange g 0 -1
<!--反向排序-->
1) "m5"
2) "m4"
3) "m3"
4) "m2"