当前位置:网站首页>Basic knowledge of redis database learning - basic, commonly used
Basic knowledge of redis database learning - basic, commonly used
2022-07-29 11:50:00 【Learning is endless】
目录
NoSQL简介
NoSQL泛指非关系型的数据库,It is to solve the problems caused by multiple data types in large-scale data sets,特别是大数据应用难题,与SQLlanguage does not conflict.
主要特点:易拓展、大数据量、高性能、灵活的数据模型、高可用.
redis简介与安装
redis是一个免费开源的NoSQL产品.
redis使用ANSI C语言编写、是一个key-value 存储系统.There are many storage types it supports,包括string(字符串)、hash(哈希)、list(列表)、set(集合)和zset(sorted set--有序集合).
redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件.
redis是一个高性能的key-value NoSQL 产品,Provides many language development interfaces,使用方便.
ubuntu下安装redis:
--切换到root账号进行操作
sudo apt update
sudo apt install redis-server
redis基本操作
1、启动服务端:redis-server
2、启动客户端:redis-cli(默认不支持中文)、redis-cli --raw(支持中文显示)
3、运行测试命令:ping
- The function is to test withredis服务器是否连通
4、切换数据库:select 1(选择编号为1的数据库)
- 数据库没有名称,默认16个,通过0-15来标识
- By default after starting the client0号数据库
5、redis键值对说明
- redis是key-value 的数据结构
- 每条数据都是一个“键值对”
- 键(key)的类型是字符串(string)
- 值(value)的类型分为5种:字符串string、哈希hash、列表list、无序集合set、有序集合zset
键命令
1、查找键
- 参数支持正则表达式,找到键,返回键名,找不到返回空
--格式
keys pattern(键名)
--例:查找所有键
keys *2、判断键是否存在
- 如果存在返回1,不存在返回0
--格式
exists key3、查看键对应的 value 类型
--格式
type key4、设置键过期时间
- 以秒为单位
- If no time is specified, it will always exist,直到使用del 删除
--格式
expire key seconds5、查看键有效时间
- 返回大于0,代表有效时间,单位:秒
- 返回-1为永久有效
- 返回-2为键不存在
--格式
ttl key字符串string
1、增加、修改
- 如果设置的键不存在则为添加,Modify if it already exists
- redis 中的字符串(string)可以用单引号、双引号、Omit the quotation marks
--设置键值
set key value
--设置键值及过期时间,以秒为单位
setex key seconds value
--设置多个键值对
mset key1 value2 key2 value2 ......
--追加值(Concatenate with the original value)
append key value2、获取
--获取单个值,不存在返回null
get key
--获取多个值
mget key1 key2 ......3、删除
--Delete keys and their corresponding values
del key1 key2 ......哈希hash
1、hash介绍
- hash用于存储“键值对”集合
- 每个哈希中的键可以理解为字段(field),一个字段(field)对应一个值(value)
- hash中的值(value)类型为字符串(string)
- 同一个哈希中字段名(field)不可以重复
2、增加、修改
- 如果设置的键不存在则为添加,Modify if it already exists
--设置单个字段
hset key field value
--设置多个字段
hmset key field1 value1 field2 value2 ......3、获取
--Get all fields of the specified key
hkeys key
--获取一个字段的值
hget key field
--获取多个字段的值
hmget key field1 field2 ......
--获取所有字段的值
hvals key
--Get all field names including their corresponding values
hgetall key4、删除
--删除hash中指定字段,The values corresponding to the fields are deleted together
hdel key field1 field2 ......
--删除整个hashKeys and Fields and Values,使用del命令
del key1 key2 ......列表list
1、list介绍
- 列表中的值(value)类型为字符串(string)
- Each value in the list is sorted in the order in which it was added
2、添加
--从左侧插入值
lpush key value1 value2 ......
--从右侧插入值
rpush key value1 value2 ......
--Inserts a value before or after the specified value
linsert key before 或 after 值 插入的值3、获取
- Returns the values in the specified range in the list
- 索引从左侧开始,第一个值的索引为0
- 索引可以是负数,表示从尾部开始计数,如:-1表示最后一个值
- start,stop 为要获取值的索引
--格式
lrange key start stop
--例:获取键keyA list of all values
lrange key 0 -14、修改
- 设置指定索引位置的值
- 索引从左侧开始,第一个值的索引为0
- 索引可以是负数,表示从尾部开始计数,如:-1表示最后一个值
--格式
lset key index value5、删除
- 删除指定值
- 将列表中前count次出现的值移除
- count > 0,从头往尾删除
- count < 0,从尾往头删除
- count = 0,删除所有值
--格式
lrem key count value无序集合 set
1、介绍
- The value of an unordered collection(value)类型为字符串(string)
- Duplicate values are not allowed in the collection
- 对于集合里的值只能添加与删除,不能修改
2、添加
--集合中添加值
sadd key value1 value2 ......3、获取
--返回所有值
smembers key4、删除
--删除指定值
srem key value有序集合 zset
1、介绍
- The median value of an ordered set(value)类型为字符串(string)
- Duplicate values are not allowed in the collection
- Each value is associated with a score(score),分数(score)可以为负数,通过分数(score)将值从小到大排序
- The values in the sorted set can only be added and deleted,不能修改
2、添加
--集合中添加值
zadd key score1 value1 score2 value2 ......3、获取
- Returns a value in the specified range
- start,stop is the subscript index of the value
- 索引从左侧开始,第一个值的索引为0
- 索引可以是负数,表示从尾部开始计数,如:-1表示最后一个值
- withscores:At the same time, the corresponding score of the value is obtained(score)
--格式
zrange key start stop [withscores]
--返回分数(score)在 min 和 max 之间的值
zrangebyscore key min max
--返回值value的分数(score)
zscore key value4、删除
--删除指定值
zrem key value1 value2 ......
--删除分数(score)A value between the specified range
zremrangebyscore key min max边栏推荐
- 【每日SQL打卡】DAY 20丨查询结果的质量和占比【难度简单】
- 宝塔快速搭建自适应咖啡网站模板与管理系统源码实测
- LeetCode_容斥原理_中等_223.矩形面积
- SQL clock 】 【 daily DAY 21 丨 report the state of the system date of continuous difficulty difficult 】 【
- 【每日SQL打卡】DAY 21丨报告系统状态的连续日期【难度困难】
- DAY 24 daily SQL clock 】 【 丨 find the beginning and end of the continuum digital difficulty moderate 】 【
- HMS Core Discovery 16 review | with tiger mound, embracing new AI "voice" state
- Peking University open classes are coming! Welcome to the "AI for science" class
- 【Unity3D】场景切换、退出全屏、退出游戏
- [image processing] image skeleton extraction based on central axis transformation with matlab code
猜你喜欢

The interviewer training courseware (very practical in-house training courseware)

QT's user-defined interface (borderless and movable)

ECCV 2022 | 基于关系查询的时序动作检测方法

ECCV 2022 | ssp: a new idea of small sample tasks with self-supporting matching

解决 Chrome 浏览器被毒霸篡改问题
![[image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code](/img/c1/f962f1c1d9f75732157d49a5d1d0d6.png)
[image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code

MarkDown高阶语法手册

Why should kubernetes be used in development environments

Summer vacation training week1

Codeforces Round #797 (Div. 3)个人题解
随机推荐
Great golang Road
ECCV 2022 | 基于关系查询的时序动作检测方法
Learn weekly - 64 - a v2ex style source BBS program
企业微信客户朋友圈一天可以发多少条?都有哪些限制?如何突破朋友圈可展示人数限制?
Design and implementation of gbase8s Informix dodker high availability cluster self recovery cluster startup command oninitdb
redis数据库基本知识学习——基础、常用
Out-of-the-box problem-solving thinking, putting a "rearview mirror" on the unconscious life
【每日SQL打卡】DAY 27丨每次访问的交易次数【难度困难-提前放出来】
2022 latest WiFi master applet independent version 3.0.8
精通音视频开发是真的可以为所欲为
递归-八皇后问题
Is this it?TypeScript actually not difficult!(recommended collection)
【表达式计算】表达式计算问题的通用解法(练习加强版,含总结)
Network layer and transport layer restrictions
IPv6 Foundation
【每日SQL打卡】DAY 21丨每个帖子的评论数【难度中等】
【每日SQL打卡】DAY 21丨报告系统状态的连续日期【难度困难】
SQL clock 】 【 daily DAY 21 丨 report the state of the system date of continuous difficulty difficult 】 【
[SwiftUI 开发] @State @Binding @ObservedObject @EnvironmentObject
Deep understanding of c # delegate into the fast lanes