首页 > 数据库 >Redis学习笔记

Redis学习笔记

时间:2023-08-25 15:01:47浏览次数:54  
标签:set redis since Redis 笔记 summary 学习 value key

1. Redis安装配置及开启自启

1.1 安装Redis依赖

Redis是基于C语言编写的,因此首先需要安装Redis所需要的gcc依赖:

yum install -y gcc tcl

1.2 安装Redis

获取Redis

cd /opt/
wget http://download.redis.io/releases/redis-6.2.6.tar.gz

解压Reids

# 解压到 /usr/local/src/ 目录下
tar -zxvf redis-6.2.6.tar.gz -C /usr/local/src/

安装Redis

cd /usr/local/src/redis-6.2.6/
#运行编译命令
make && make install

如果没有出错,应该就安装成功了。

默认的安装路径是在 /usr/local/bin目录下:

image-20230823144056752.png

该目录以及默认配置到环境变量,因此可以在任意目录下运行这些命令。其中:

  • redis-cli:是redis提供的命令行客户端
  • redis-server:是redis的服务端启动脚本
  • redis-sentinel:是redis的哨兵启动脚本

1.3 Redis启动方式

默认启动

cd /usr/local/bin/
redis-server 

image-20230823144228645.png

这种启动属于前台启动,会阻塞整个会话窗口,窗口关闭或者按下CTRL + C则Redis停止。不推荐使用。

指定配置启动

如果要让Redis以后台方式启动,则必须修改Redis配置文件,就在我们之前解压的redis安装包下的redis.conf

我们先将这个配置文件备份一份:

cd /usr/local/src/redis-6.2.6/
cp redis.conf redis.conf.bck

然后修改redis.conf文件中的一些配置:

# 允许访问的地址,默认是127.0.0.1,会导致只能在本地访问。修改为0.0.0.0则可以在任意IP访问,生产环境不要设置为0.0.0.0
bind 0.0.0.0
# 守护进程,修改为yes后即可后台运行
daemonize yes 
# 密码,设置后访问Redis必须输入密码
requirepass 123321

Redis的其它常见配置:

# 监听的端口
port 6379
# 工作目录,默认是当前目录,也就是运行redis-server时的命令,日志、持久化等文件会保存在这个目录
dir .
# 数据库数量,设置为1,代表只使用1个库,默认有16个库,编号0~15
databases 1
# 设置redis能够使用的最大内存
maxmemory 512mb
# 日志文件,默认为空,不记录日志,可以指定日志文件名
logfile "redis.log"

启动Redis:

redis-server /usr/local/src/redis-6.2.6/redis.conf

停止服务:

# 利用redis-cli来执行 shutdown 命令,即可停止 Redis 服务,
# 因为之前配置了密码,因此需要通过 -u 来指定密码
redis-cli -a 123321 shutdown

开机自启

通过配置来实现开机自启。

首先,新建一个系统服务文件:

vi /etc/systemd/system/redis.service

内容如下:

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /usr/local/src/redis-6.2.6/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

设置开机自启:

#重载系统服务
systemctl daemon-reload
# 启动
systemctl start redis
# 停止
systemctl stop redis
# 重启
systemctl restart redis
# 查看状态
systemctl status redis
# 开机自启
systemctl enable redis

image-20230823150911575.png

2.Redis客户端

安装完成Redis,我们就可以操作Redis,实现数据的CRUD了。这需要用到Redis客户端,包括:

  • 命令行客户端
  • 图形化桌面客户端
  • 编程客户端

2.1.Redis命令行客户端

Redis安装完成后就自带了命令行客户端:redis-cli,使用方式如下:

redis-cli [options] [commonds]

其中常见的options有:

  • -h 127.0.0.1:指定要连接的redis节点的IP地址,默认是127.0.0.1
  • -p 6379:指定要连接的redis节点的端口,默认是6379
  • -a 123321:指定redis的访问密码

其中的commonds就是Redis的操作命令,例如:

  • ping:与redis服务端做心跳测试,服务端正常会返回pong

不指定commond时,会进入redis-cli的交互控制台:

image-20230823151344367.png

2.2.图形化桌面客户端

图形化客户端链接

image-20230823151517595.png

下载后直接安装,点击即可连接Reids

image-20230823152143144.png

注意Linux 需开启防火墙,云服务器还需开启云服务器防火墙

# 查看所有允许的防火墙端口
sudo firewall-cmd --zone=public --list-all
# 添加 Redis 端口
sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
# 重新加载
sudo firewall-cmd --reload

3.Redis命令

3.1Redis通用命令

KEYS

127.0.0.1:6379> help KEYS

  KEYS pattern
  summary: Find all keys matching the given pattern
  since: 1.0.0
  group: generic

pattern是一个用于匹配键的模式,可以包含通配符*?

示例:

  • 获取所有键:

    KEYS *
    
  • 获取以"mykey"开头的所有键:

    KEYS mykey*
    
  • 获取以"my"开头且以"key"结尾的所有键:

    KEYS my*key
    

注意事项:

  • KEYS命令在大型数据库中使用时可能会影响性能,因为它会阻塞Redis服务器,直到所有匹配的键都被迭代完毕。因此,在生产环境中,应谨慎使用KEYS命令。如果需求是获取某种特定类型的键,可以考虑使用更具体的命令,如SCANTYPE
  • 可以使用SCAN命令代替KEYS命令来逐步迭代匹配的键,以避免对Redis服务器的阻塞。

DEL

127.0.0.1:6379> help DEL

  DEL key [key ...]
  summary: Delete a key
  since: 1.0.0
  group: generic

其中,key是要删除的键的名称,可以同时指定多个键。

示例:

DEL mykey1 mykey2 

如果删除成功,DEL命令将返回被删除键的数量。如果某个键不存在,将被视为已成功删除。如果所有的键都不存在,DEL命令将返回0。

需要注意的是,DEL命令是一个原子操作,即要么所有键都被删除,要么没有键被删除。

EXISTS

127.0.0.1:6379> help EXISTS

  EXISTS key [key ...]
  summary: Determine if a key exists
  since: 1.0.0
  group: generic

示例:

  1. 检查键名为"mykey"的键是否存在:

    EXISTS mykey 
    

    返回值为1或0,表示键是否存在。

  2. 批量检查多个键是否存在:

    EXISTS key1 key2 key3 ...
    

    可以一次性检查多个键的存在性,返回一个包含对应键的存在状态的数组。

请注意,EXISTS命令用于检查单个键的存在性,如果要检查多个键的存在性,可以使用MGET命令或者管道技术。

EXPIRE | TTL | PERSIST

127.0.0.1:6379> help EXPIRE

  EXPIRE key seconds
  summary: Set a key's time to live in seconds
  since: 1.0.0
  group: generic

127.0.0.1:6379> help TTL

  TTL key
  summary: Get the time to live for a key
  since: 1.0.0
  group: generic

127.0.0.1:6379> help PERSIST

  PERSIST key
  summary: Remove the expiration from a key
  since: 2.2.0
  group: generic
  1. 设置键的过期时间:

    EXPIRE key seconds 
    
    • key是要设置过期时间的键名。
    • seconds是键的过期时间,以秒为单位。在指定的秒数后,键将自动被删除。

    示例:

    EXPIRE mykey 60
    

    上述命令将mykey键设置为60秒后过期。

  2. 检查键的剩余生存时间:

    TTL key
    
    • key是要检查的键名。

    示例:

    TTL mykey 
    

    上述命令将返回mykey键的剩余生存时间(以秒为单位)。如果键不存在或已过期,则返回-2;如果键存在但没有设置过期时间,则返回-1;否则返回键的剩余生存时间。

  3. 移除键的过期时间,使其永久保持:

    PERSIST key
    
    • key是要移除过期时间的键名。

    示例:

    PERSIST mykey
    

    上述命令将移除mykey键的过期时间。

3.2 String类型

语法操作

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

bikey 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

GETDEL key
summary: Get the value of a key and delete the key
since: 6.2.0

GETEX key [EX seconds|PX milliseconds|EXAT timestamp|PXAT milliseconds-timestamp|PERSIST]
summary: Get the value of a key and optionally set its expiration
since: 6.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|EXAT timestamp|PXAT milliseconds-timestamp|KEEPTTL] [NX|XX] [GET]
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

STRALGO LCS algo-specific-argument [algo-specific-argument ...]
summary: Run algorithms (currently LCS) against strings
since: 6.0.0

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

key的层级结构

推荐key格式:[项目名]:[业务名]:[类型]:[id]

127.0.0.1:6379> set xy:user:1 '{"id":1, "name":"Jack", "age": 21}'
OK
127.0.0.1:6379> set xy:user:2 '{"id":2, "name":"Rose", "age": 18}'
OK
127.0.0.1:6379> set xy:product:1 '{"id":1, "name":"小米11", "price": 4999}'
OK
127.0.0.1:6379> set xy:product:2 '{"id":2, "name":"荣耀6", "price": 2999}'
OK
127.0.0.1:6379> keys *
1) "xy:user:1"
2) "xy:user:2"
3) "xy:product:1"
4) "xy:product:2"

image-20230823173616668

3.3 Hset类型

语法操作

127.0.0.1:6379> help @hash

  HDEL key field [field ...]
  summary: Delete one or more hash fields
  since: 2.0.0

  HEXISTS key field
  summary: Determine if a hash field exists
  since: 2.0.0

  HGET key field
  summary: Get the value of a hash field
  since: 2.0.0

  HGETALL key
  summary: Get all the fields and values in a hash
  since: 2.0.0

  HINCRBY key field increment
  summary: Increment the integer value of a hash field by the given number
  since: 2.0.0

  HINCRBYFLOAT key field increment
  summary: Increment the float value of a hash field by the given amount
  since: 2.6.0

  HKEYS key
  summary: Get all the fields in a hash
  since: 2.0.0

  HLEN key
  summary: Get the number of fields in a hash
  since: 2.0.0

  HMGET key field [field ...]
  summary: Get the values of all the given hash fields
  since: 2.0.0

  HMSET key field value [field value ...]
  summary: Set multiple hash fields to multiple values
  since: 2.0.0

  HRANDFIELD key [count [WITHVALUES]]
  summary: Get one or multiple random fields from a hash
  since: 6.2.0

  HSCAN key cursor [MATCH pattern] [COUNT count]
  summary: Incrementally iterate hash fields and associated values
  since: 2.8.0

  HSET key field value [field value ...]
  summary: Set the string value of a hash field
  since: 2.0.0

  HSETNX key field value
  summary: Set the value of a hash field, only if the field does not exist
  since: 2.0.0

  HSTRLEN key field
  summary: Get the length of the value of a hash field
  since: 3.2.0

  HVALS key
  summary: Get all the values in a hash
  since: 2.0.0

3.4 List类型

语法操作

127.0.0.1:6379> help @list

  BLMOVE source destination LEFT|RIGHT LEFT|RIGHT timeout
  summary: Pop an element from a list, push it to another list and return it; or block until one is available
  since: 6.2.0

  BLPOP key [key ...] timeout
  summary: Remove and get the first element in a list, or block until one is available
  since: 2.0.0

  BRPOP key [key ...] timeout
  summary: Remove and get the last element in a list, or block until one is available
  since: 2.0.0

  BRPOPLPUSH source destination timeout
  summary: Pop an element from a list, push it to another list and return it; or block until one is available
  since: 2.2.0

  LINDEX key index
  summary: Get an element from a list by its index
  since: 1.0.0

  LINSERT key BEFORE|AFTER pivot element
  summary: Insert an element before or after another element in a list
  since: 2.2.0

  LLEN key
  summary: Get the length of a list
  since: 1.0.0

  LMOVE source destination LEFT|RIGHT LEFT|RIGHT
  summary: Pop an element from a list, push it to another list and return it
  since: 6.2.0

  LPOP key [count]
  summary: Remove and get the first elements in a list
  since: 1.0.0

  LPOS key element [RANK rank] [COUNT num-matches] [MAXLEN len]
  summary: Return the index of matching elements on a list
  since: 6.0.6

  LPUSH key element [element ...]
  summary: Prepend one or multiple elements to a list
  since: 1.0.0

  LPUSHX key element [element ...]
  summary: Prepend an element to a list, only if the list exists
  since: 2.2.0

  LRANGE key start stop
  summary: Get a range of elements from a list
  since: 1.0.0

  LREM key count element
  summary: Remove elements from a list
  since: 1.0.0

  LSET key index element
  summary: Set the value of an element in a list by its index
  since: 1.0.0

  LTRIM key start stop
  summary: Trim a list to the specified range
  since: 1.0.0

  RPOP key [count]
  summary: Remove and get the last elements in a list
  since: 1.0.0

  RPOPLPUSH source destination
  summary: Remove the last element in a list, prepend it to another list and return it
  since: 1.2.0

  RPUSH key element [element ...]
  summary: Append one or multiple elements to a list
  since: 1.0.0

  RPUSHX key element [element ...]
  summary: Append an element to a list, only if the list exists
  since: 2.2.0

3.5 Set类型

语法介绍

127.0.0.1:6379> help @set

  SADD key member [member ...]
  summary: Add one or more members to a set
  since: 1.0.0

  SCARD key
  summary: Get the number of members in a set
  since: 1.0.0

  SDIFF key [key ...]
  summary: Subtract multiple sets
  since: 1.0.0

  SDIFFSTORE destination key [key ...]
  summary: Subtract multiple sets and store the resulting set in a key
  since: 1.0.0

  SINTER key [key ...]
  summary: Intersect multiple sets
  since: 1.0.0

  SINTERSTORE destination key [key ...]
  summary: Intersect multiple sets and store the resulting set in a key
  since: 1.0.0

  SISMEMBER key member
  summary: Determine if a given value is a member of a set
  since: 1.0.0

  SMEMBERS key
  summary: Get all the members in a set
  since: 1.0.0

  SMISMEMBER key member [member ...]
  summary: Returns the membership associated with the given elements for a set
  since: 6.2.0

  SMOVE source destination member
  summary: Move a member from one set to another
  since: 1.0.0

  SPOP key [count]
  summary: Remove and return one or multiple random members from a set
  since: 1.0.0

  SRANDMEMBER key [count]
  summary: Get one or multiple random members from a set
  since: 1.0.0

  SREM key member [member ...]
  summary: Remove one or more members from a set
  since: 1.0.0

  SSCAN key cursor [MATCH pattern] [COUNT count]
  summary: Incrementally iterate Set elements
  since: 2.8.0

  SUNION key [key ...]
  summary: Add multiple sets
  since: 1.0.0

  SUNIONSTORE destination key [key ...]
  summary: Add multiple sets and store the resulting set in a key
  since: 1.0.0

3.6 SortedSet类型

语法介绍

127.0.0.1:6379> help @sorted_set

  BZPOPMAX key [key ...] timeout
  summary: Remove and return the member with the highest score from one or more sorted sets, or block until one is available
  since: 5.0.0

  BZPOPMIN key [key ...] timeout
  summary: Remove and return the member with the lowest score from one or more sorted sets, or block until one is available
  since: 5.0.0

  ZADD key [NX|XX] [GT|LT] [CH] [INCR] score member [score member ...]
  summary: Add one or more members to a sorted set, or update its score if it already exists
  since: 1.2.0

  ZCARD key
  summary: Get the number of members in a sorted set
  since: 1.2.0

  ZCOUNT key min max
  summary: Count the members in a sorted set with scores within the given values
  since: 2.0.0

  ZDIFF numkeys key [key ...] [WITHSCORES]
  summary: Subtract multiple sorted sets
  since: 6.2.0

  ZDIFFSTORE destination numkeys key [key ...]
  summary: Subtract multiple sorted sets and store the resulting sorted set in a new key
  since: 6.2.0

  ZINCRBY key increment member
  summary: Increment the score of a member in a sorted set
  since: 1.2.0

  ZINTER numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX] [WITHSCORES]
  summary: Intersect multiple sorted sets
  since: 6.2.0

  ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
  summary: Intersect multiple sorted sets and store the resulting sorted set in a new key
  since: 2.0.0

  ZLEXCOUNT key min max
  summary: Count the number of members in a sorted set between a given lexicographical range
  since: 2.8.9

  ZMSCORE key member [member ...]
  summary: Get the score associated with the given members in a sorted set
  since: 6.2.0

  ZPOPMAX key [count]
  summary: Remove and return members with the highest scores in a sorted set
  since: 5.0.0

  ZPOPMIN key [count]
  summary: Remove and return members with the lowest scores in a sorted set
  since: 5.0.0

  ZRANDMEMBER key [count [WITHSCORES]]
  summary: Get one or multiple random elements from a sorted set
  since: 6.2.0

  ZRANGE key min max [BYSCORE|BYLEX] [REV] [LIMIT offset count] [WITHSCORES]
  summary: Return a range of members in a sorted set
  since: 1.2.0

  ZRANGEBYLEX key min max [LIMIT offset count]
  summary: Return a range of members in a sorted set, by lexicographical range
  since: 2.8.9

  ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
  summary: Return a range of members in a sorted set, by score
  since: 1.0.5

  ZRANGESTORE dst src min max [BYSCORE|BYLEX] [REV] [LIMIT offset count]
  summary: Store a range of members from sorted set into another key
  since: 6.2.0

  ZRANK key member
  summary: Determine the index of a member in a sorted set
  since: 2.0.0

  ZREM key member [member ...]
  summary: Remove one or more members from a sorted set
  since: 1.2.0

  ZREMRANGEBYLEX key min max
  summary: Remove all members in a sorted set between the given lexicographical range
  since: 2.8.9

  ZREMRANGEBYRANK key start stop
  summary: Remove all members in a sorted set within the given indexes
  since: 2.0.0

  ZREMRANGEBYSCORE key min max
  summary: Remove all members in a sorted set within the given scores
  since: 1.2.0

  ZREVRANGE key start stop [WITHSCORES]
  summary: Return a range of members in a sorted set, by index, with scores ordered from high to low
  since: 1.2.0

  ZREVRANGEBYLEX key max min [LIMIT offset count]
  summary: Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.
  since: 2.8.9

  ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
  summary: Return a range of members in a sorted set, by score, with scores ordered from high to low
  since: 2.2.0

  ZREVRANK key member
  summary: Determine the index of a member in a sorted set, with scores ordered from high to low
  since: 2.0.0

  ZSCAN key cursor [MATCH pattern] [COUNT count]
  summary: Incrementally iterate sorted sets elements and associated scores
  since: 2.8.0

  ZSCORE key member
  summary: Get the score associated with the given member in a sorted set
  since: 1.2.0

  ZUNION numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX] [WITHSCORES]
  summary: Add multiple sorted sets
  since: 6.2.0

  ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
  summary: Add multiple sorted sets and store the resulting sorted set in a new key
  since: 2.0.0

标签:set,redis,since,Redis,笔记,summary,学习,value,key
From: https://blog.51cto.com/learningfish/7231145

相关文章

  • IM跨平台技术学习(八):新QQ桌面版为何选择Electron作为跨端框架
    本文由QQ技术团队王辉、吴浩、陈俊文分享,编辑Tina整理,本文收录时有内容修订和排版优化。1、引言在瞬息万变的互联网行业中,年过二十四的即时通讯IM应用QQ堪称超长寿的产品,见证了中国互联网崛起的完整历程。然而,如今这个元老级产品经历了一次从内到外彻底的重构。在这次重构......
  • Redis开启过期监听
    1.开启过期通知配置默认notify-keyspace-events""修改为:notify-keyspace-eventsEx2.增加监听类publicclassRedisKeyExpirationListenerextendsKeyExpirationEventMessageListener{publicRedisKeyExpirationListener(RedisMessageListenerContainerlisten......
  • mormot2 笔记(三) 实体转JSON
    TOL=class(TObject)publicprocedureW(W:TJsonWriter;Instance:TObject;Options:TTextWriterWriteObjectOptions);end;TPerson=classprivateFName:string;FID:integer;FSex:Byte;publishedpropertyID:integerread......
  • LangChain-Chatchat学习资料-Windows开发部署(踩坑篇)
    LangChain-Chatchat学习资料-Windows开发部署(踩坑篇)环境准备的坑1.CUDA版本问题我是用的RTX3060显卡,通过nvidia-smi命令,查看显卡支持的CUDA版本为12.2,然后下载版本的CUDA,后续发现这里是个坑,pytorch目前最新版为2.0.1,支持的cuda版本最高为11.8,所以想使用显卡跑pytorch,需要讲CUDA......
  • Redis如何批量删除指定前缀的key
    批量删除指定前缀的Key有两中方法,一种是借助redis-cli,另一种是通过SCAN命令来遍历所有匹配前缀的key,并使用DEL命令逐个删除它们。redis-cli使用Redis自带的redis-cli命令行工具,你可以通过以下方式批量删除指定前缀的key:redis-cliKEYS"your_prefix*"|xargsredis......
  • Robot 框架学习笔记
    Robot框架学习笔记为了更好地让读者理解快速学习新框架的思路,笔者接下来会继续介绍另一个名为Robot的自动化测试框架,希望读者能参考笔者从零开始讲解一个开发/测试框架的流程,从中总结出适合于自己的快速学习方法。与Selenium框架相比,Robot框架是一款更为通用的、可扩展的......
  • springboot整合redis回滚
    1:添加依赖2:yml中配置连接,如:host,password,port3:@autowired注解注入Redistemplate调用方法生成对象 为了方便公司开发,一般会对数据进行序列化存储,这时需要创建配置类进行全局设置packagecom.example.config;importcom.fasterxml.jackson.annotation.JsonAutoDetect;importco......
  • [算法学习笔记] 换根dp
    换根dp一般不会指定根节点,并且根节点的变化会对一些值进行改变。因此我们需要转移根。换根dp一般需要预处理一下一个节点的值,然后对于任意节点开始树上dp转移。所以我们常用两次dfs,第一次dfs预处理,第二次dfs为树上dp。一般比较套路。接下来会给出一个典型例题。典例1:L......
  • LangChain-Chatchat学习资料-Windows开发部署
    在windows10下的安装部署参考资料1.LacnChain-Chatchat项目基础环境准备本人使用的是Windows10专业版22H2版本,已经安装了Python3.10,CUDA11.8版本,miniconda3。硬件采用联想R9000P,AMDR75800H,16G内存,RTX30606G。安装依赖#使用conda安装激活环境condacreate-nLangchain......
  • 拓扑排序学习笔记
    思想拓扑,一看就是从图的开始开始开拓,并按被开拓到的顺序排序拓扑排序的思想如下:将入度为\(0\)的点删除,并记录它被删除的顺序,直到没有点则结束程序图解如本图的拓扑序就为123541.发现1入度为0删除1,2/3的入度减\(1\)2.发现2入度为0删除2,5的入度减\(1\)3.发现3......