redis连接服务器,五大数据类型

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 -h 172.26.77.93 -p 6379

7. redis五大类型:string类型 hash list set 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
string
127.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) 1
127.0.0.1:6379> get o
"1"
127.0.0.1:6379> incr o
(integer) 2
127.0.0.1:6379> get o
"2"
127.0.0.1:6379> incrby o 5 //增加5,这种方式只能用于增加整数
(integer) 7
127.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) 2
127.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"
hash 哈希
127.0.0.1:6379> hset xiaoshuo name shengxu
(integer) 1
127.0.0.1:6379> hset xiaoshuo author chengdong
(integer) 1
127.0.0.1:6379> hset xiaoshuo desc haokan
(integer) 1
127.0.0.1:6379> keys *
1) "p"
2) "q"
3) "xiaoshuo"
127.0.0.1:6379> hgetall xiaoshuo
1) "name"
2) "shengxu"
3) "author"
4) "chengdong"
5) "desc"
6) "haokan"
127.0.0.1:6379> hkeys xiaoshuo
1) "name"
2) "author"
3) "desc"
127.0.0.1:6379> hvals xiaoshuo
1) "shengxu"
2) "chengdong"
3) "haokan"
127.0.0.1:6379> hdel xiaoshuo author
(integer) 1
127.0.0.1:6379> hkeys xiaoshuo
1) "name"
2) "desc"
list 列表 双向链表
127.0.0.1:6379> lpush lt coco haha lala
//从左边插入数据,后面的会覆盖前面的
(integer) 3
127.0.0.1:6379> lrange lt 0 -1
1) "lala"
2) "haha"
3) "coco"
127.0.0.1:6379> rpush lt xixi hehe huohuo
//从又边插入数据
(integer) 6
127.0.0.1:6379> lrange lt 0 -1
1) "lala"
2) "haha"
3) "coco"
4) "xixi"
5) "hehe"
6) "huohuo"
127.0.0.1:6379> lpop lt
//从左边删除一个值
"lala"
127.0.0.1:6379> lrange lt 0 -1
1) "haha"
2) "coco"
3) "xixi"
4) "hehe"
5) "huohuo"


set 集合
127.0.0.1:6379> sadd r 1 2 3 
(integer) 3
127.0.0.1:6379> scard r
(integer) 3
127.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"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值