Redis(非关系型数据库)入门指南

redis

官网: www.redis.cn

1.1redis是什么?

Remote Dictionary Server(Redis): key-value的储存系统,非关系型数据库
意大利人开发:Salvatore Sanfilippo
ANSI C语言开发的,基于内存、分布式、可持久化的键值对数据库。

1.2 redis的特点

1.支持持久化–内存–磁盘
2.开源BSD协议,高性能key-value
3.Redis实现单线程(目前版本)。在内存中切换,速度特别快,所以可以单线程,好处是不用考虑线程安全。
4.五大类型:String,list,set(不可重复),hash,zset(可排序)
5.性能极高–读的速度110000次/秒,写的速度81000次/秒

1.3 基本命令

1.cmd中输入redis-cil+回车+输入ping+回车=PONG,证明安装成功
,并进入Redis在这里插入图片描述> 2.测试电脑读写速度
redis-benchmark -n 10000 -q

3.基本命令

  1. ( set animal cat):存入数据set
127.0.0.1:6379> set animal cat
OK
  1. (get animal) :取出数据get
127.0.0.1:6379> get animal
"cat"

3.(key *):查询所有key

127.0.0.1:6379> keys *
1) "myset:__rand_int__"
2) "mylist"
3) "animal"
4) "counter:__rand_int__"
5) "key:__rand_int__"

4.(del animal):删除指定key

127.0.0.1:6379> del animal
(integer) 1

5.(expire):指定时间让指定key删除

127.0.0.1:6379> expire animal 5
(integer) 1
127.0.0.1:6379> get animal
(nil)

在这里插入图片描述

1.4 五大类型

1.4.1 hash类型

redis : key : value
car : brand(benz) ,price(12300)

1.hset : 存储数据
hset key 属性 值 属性 值 属性 值

127.0.0.1:6379> hset benz_car brand benz color bule price 1900000.00
(integer) 3

2.hget: 取出单个数据
hget key 属性

127.0.0.1:6379> hget benz_car price
"1900000.00"
127.0.0.1:6379> hget benz_car color
"bule"

3.hmget: 取出多个数据
hget key 属性 属性 …

127.0.0.1:6379> hmget benz_car color price brand
1) "bule"
2) "1900000.00"
3) "benz"

1.4.2 list类型

lpush:从左边加入队列
Irange:从左边加入队列

127.0.0.1:6379> Lpush names tom rose jack
(integer) 3
127.0.0.1:6379> Lrange names 0 3
1) "jack"
2) "rose"
3) "tom"

1.4.3 set类型

类似list,但是不允许重复,和java里一样

127.0.0.1:6379> sadd booktitles c++ c++ java java python
(integer) 3
127.0.0.1:6379> smembers booktitles
1) "python"
2) "java"
3) "c++"

list的Lpush可以存重复数据

127.0.0.1:6379>   Lpush booktitles02  c++ c++ java java python
(integer) 5
127.0.0.1:6379>  Lrange booktitles02 0 5
1) "python"
2) "java"
3) "java"
4) "c++"
5) "c++"

1.4.4 sorted sets类型

zadd key 权重 属性 权重 属性 权重 属性… 权重 属性
zrange key start stop(从小到大)

127.0.0.1:6379> zadd goods 20.00 paper 15 drink 30 coffe 8 ice-cream
(integer) 4
127.0.0.1:6379> zrange goods 0 4
1) "ice-cream"
2) "drink"
3) "paper"
4) "coffe"

zrevrange key start stop(从大到小)

127.0.0.1:6379> zrevrange goods 0 4
1) "coffe"
2) "paper"
3) "drink"
4) "ice-cream"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值