缓存技术
cookie和session
Cookie:客户端保存用户信息的一种机制
Session:(会话控制)服务器端保存一个数据结构,用来追踪用户的状态,session对象存储特定用户会话所需的属性及配置信息。这个数据可以保存在集群、数据库、文件中。
Session维护用户登录状态过程:
用户提交登录表单,request
服务端校验用户名和密码
通过后把用户信息存储到redis中,key为session_id
server返回的respone中的set-cookie字段包含该session_id,client收到后存入cookie中,
client再次向服务器发送请求时,会在请求头中添加自己的cookie信息,server收到后提取出并在redis中找到该session,完成业务操作。
(多图下次补上)
sticky和non-sticky
sticky:粘性
non-sticky:非粘性
redis部署与使用
CentOS8中自带的yum仓库中的redis
[root@centos8 ~]#dnf info redis
Last metadata expiration check: 0:00:16 ago on Wed 13 Jul 2022 05:08:31 AM CST.
Available Packages
Name : redis
Version : 5.0.3
Release : 5.module_el8.4.0+955+7126e393
Architecture : x86_64
Size : 927 k
Source : redis-5.0.3-5.module_el8.4.0+955+7126e393.src.rpm
Repository : appstream
Summary : A persistent key-value database
URL : http://redis.io
License : BSD and MIT
Description : Redis is an advanced key-value store. It is often referred to as a data
: structure server since keys can contain strings, hashes, lists, sets and
: sorted sets.
:
: You can run atomic operations on these types, like appending to a string;
: incrementing the value in a hash; pushing to a list; computing set
: intersection, union and difference; or getting the member with highest
: ranking in a sorted set.
:
: In order to achieve its outstanding performance, Redis works with an
: in-memory dataset. Depending on your use case, you can persist it either
: by dumping the dataset to disk every once in a while, or by appending
: each command to a log.
:
: Redis also supports trivial-to-setup master-slave replication, with very
: fast non-blocking first synchronization, auto-reconnection on net split
: and so forth.
:
: Other features include Transactions, Pub/Sub, Lua scripting, Keys with a
: limited time-to-live, and configuration settings to make Redis behave like
: a cache.
:
: You can use Redis from most programming languages also.
编译安装
略