Redis入门

Redis简介

海量用户,高并发的情况下,容易出现性能问题的主要原因有:

  • 性能瓶颈:磁盘IO性能低下;
  • 扩展瓶颈: 数据关系复杂,扩展性差,不便于大规模集群;

解决思路:

  • 降低磁盘IO次数,越低越好;
  • 去除数据间关系,越简单越好

Nosql

Nosql: Not-only SQL(泛指非关系型的数据库),作为关系型数据库的补充。
作用:应用基于海量用户和海量数据前提下的数据处理问题。
特征:

  • 可扩容,可伸缩
  • 大数据量下高性能
  • 灵活的数据模型
  • 高可用

常见的Nosql数据库:

  • Redis
  • memcache
  • HBase
  • MongoDB

解决方案(电商场景)

-1.商品基本信息 (Mysql)

  • 名称
  • 价格
  • 厂商

-2.商品附加信息 (MongoDB)

  • 描述
  • 详情
  • 评论

-3.图片信息 (分布式文件系统)
-4.搜索关键字 (ES、Lucene、solr)
-5.热点信息 (Redis、memcache、tair)

  • 高频
  • 波段性

Redis简介

概念: Redis(REmote DIctionary Server)C语音开发的一个开源的高性能键值对(key-value)数据库。
特征:

  • 数据间没有必然的关联关系
  • 内部采用单线程机制工作
  • 高性能,官方测试数据,50个并发执行100000个请求,读的速度是110000次/s, 写的速度是81000次/s
  • 多数据类型支持
    字符串类型 string
    列表类型 list
    散列类型 hash
    集合类型 set
    有序集合类型 sorted_set
  • 持久化支持。可以进行数据灾难恢复

Redis的应用

  • 为热点数据加速查询(主要场景),如热点商品、热点新闻
  • 任务队列,如秒杀、抢购、购票排队
  • 即时信息查询,如各位排行榜、各类网站访问统计、在线人数统计
  • 时效性信息控制,如验证码控制、投屏控制等
  • 分布式数据共享,如分布式集群架构中的session分离
  • 消息队列
  • 分布式锁

Redis的下载与安装

Linux版(适用于企业级开发)

  • Redis高级开发使用
  • 以4.0版本作为主版本

Windows版本(适合零基础学习)

在这里插入图片描述
服务端启动
客户端启动

Redis的基本操作

命令行模式工具使用思考

  • 功能性命令
  • 清除屏幕信息
  • 帮助信息查询
  • 退出指令

信息添加

  • 功能: 设置key,value数据
  • 命令 set key value
  • 范例 set name helloworld

信息查询

  • 功能: 根据可以查询对应的value,如果不存在,返回空(nil)
  • 命令 get key
127.0.0.1:6379> set name helloworld
OK
127.0.0.1:6379> get name
"helloworld"

清除屏幕信息

  • 功能:清除屏幕中的信息
  • 命令 clear

帮助

  • 功能:获取命令帮助文档,获取组中所有命令信息名称
  • 命令 help 命令名称 help @组名
127.0.0.1:6379> help get

  GET key
  summary: Get the value of a key
  since: 1.0.0
  group: string
127.0.0.1:6379> help
redis-cli 3.2.100
To get help about Redis commands type:
      "help @<group>" to get a list of commands in <group>
      "help <command>" for help on <command>
      "help <tab>" to get a list of possible help topics
      "quit" to exit

To set redis-cli perferences:
      ":set hints" enable online hints
      ":set nohints" disable online hints
Set your preferences in ~/.redisclirc
127.0.0.1:6379> help @string

  APPEND key value
  summary: Append a value to a key
  since: 2.0.0

  BITCOUNT key [start end]
  summary: Count set bits in a string
  since: 2.6.0

  BITFIELD key [GET type offset] [SET type offset value] [INCRBY type offset increment] [OVERFLOW WRAP|SAT|FAIL]
  summary: Perform arbitrary bitfield integer operations on strings
  since: 3.2.0

  BITOP operation destkey key [key ...]
  summary: Perform bitwise operations between strings
  since: 2.6.0

  BITPOS key bit [start] [end]
  summary: Find first bit set or clear in a string
  since: 2.8.7

  DECR key
  summary: Decrement the integer value of a key by one
  since: 1.0.0

  DECRBY key decrement
  summary: Decrement the integer value of a key by the given number
  since: 1.0.0

  GET key
  summary: Get the value of a key
  since: 1.0.0

  GETBIT key offset
  summary: Returns the bit value at offset in the string value stored at key
  since: 2.2.0

  GETRANGE key start end
  summary: Get a substring of the string stored at a key
  since: 2.4.0

  GETSET key value
  summary: Set the string value of a key and return its old value
  since: 1.0.0

  INCR key
  summary: Increment the integer value of a key by one
  since: 1.0.0

  INCRBY key increment
  summary: Increment the integer value of a key by the given amount
  since: 1.0.0

  INCRBYFLOAT key increment
  summary: Increment the float value of a key by the given amount
  since: 2.6.0

  MGET key [key ...]
  summary: Get the values of all the given keys
  since: 1.0.0

  MSET key value [key value ...]
  summary: Set multiple keys to multiple values
  since: 1.0.1

  MSETNX key value [key value ...]
  summary: Set multiple keys to multiple values, only if none of the keys exist
  since: 1.0.1

  PSETEX key milliseconds value
  summary: Set the value and expiration in milliseconds of a key
  since: 2.6.0

  SET key value [EX seconds] [PX milliseconds] [NX|XX]
  summary: Set the string value of a key
  since: 1.0.0

  SETBIT key offset value
  summary: Sets or clears the bit at offset in the string value stored at key
  since: 2.2.0

  SETEX key seconds value
  summary: Set the value and expiration of a key
  since: 2.0.0

  SETNX key value
  summary: Set the value of a key, only if the key does not exist
  since: 1.0.0

  SETRANGE key offset value
  summary: Overwrite part of a string at key starting at the specified offset
  since: 2.2.0

  STRLEN key
  summary: Get the length of the value stored in a key
  since: 2.2.0

在这里插入图片描述

退出客户端命令

quit
exit
<ESC>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值