当前位置:网站首页>Redis database and project framework
Redis database and project framework
2022-07-23 11:15:00 【ZXY_ lucky】
1. install redis
1. Download zip
Download address :https://github.com/tporadowski/redis/releases
spare :https://hub.fastgit.xyz/tporadowski/redis/releases Bear in mind : Don't log in to your own account on the mirror website
2. Decompress package , Create a folder , Put the solved folder in the created folder
3. Configure environment variables
Is to create the root directory of the file into the environment variable
4. Register and bind the configuration file used
redis-server --service-install Profile address # Installation services
redis-server --service-uninstall # Uninstall service
5. start-up server Program
redis-server --service-start # start-up redis The server
redis-server --service-stop # stop it redis The server
6. restart redis The server
redis Five data types
- String String type
- List list
- Hash Hash guns={‘name’:‘haha’}
- Set Unordered list
- Zset Ordered list Default from small to large
General Command
select 2 # Switch to 2 library The default is 0, Optional 0-15 Yes 16 Databases
keys * # Query all the keys
exists name # Confirm whether the key exists
type name # View key type
rename key newkey # Change key name
del name # Delete key
flushdb # Empty the current library
flushall # Empty all libraries
Common commands
String type
1. Database notation
# increase
set key value # Create a key-value
mset key1 value1 key2 value2... # Create multiple
set key value ex 10 # Set expiration date
set key value nx # When key non-existent , Will be deposited
# check
get key # View one key Value
mget key1 key2.. # obtain
strlen key1 # obtain key length
# Change
set key newvalue # modify key Value
mset key1 newvalue1 key2 newvalue2..# Multiple modifications
# Modify part of string , From the position 1 Start modifying characters , With asdv Cover
setrange key 1 asdv
append key value # Additional
# string There are special numbers
incr key # Self increasing 1
decr key # Self reduction 1
incrby key 5 # Self increasing 5
decrby key 5 # Self reduction 5
2.python How to write it
import redis
# db Do not write default is 0 No password can be left blank host Write 127.0.0.1 hurry up
r = redis.Redis(host='127.0.0.1',port=6379,password='123123',db=0)
r.set("name","haha")
r.mset({
"name":"haha","age":23})
# obtain key value
r.get("name") # Return string
r.mget("name","age") # Return value list
# Set expiration time
r.set("name","haha",ex=10)
# Created when not present
r.set("name","haha",nx=True)
# Get string length ,int
r.strlen("name")
Set type ( Unordered list , unordered set )
# increase
sadd key value1 value2 value3
# check
smembers key # Check all personnel
scard key # Check how many players are in the current room
sismember key value # Judge value Whether to join the game
# Change
srem key value1 value2 # Well value1,value2 remove
Zset type ( Ordered set )
# increase
zadd guns 30 ak47 47 dp28 100 m247
# check
zrange guns 0 -1 # see guns, Sort from small to large
zrevrange guns 0 -1 # From big to small
zrangebyscore guns (40 100 # stay (40-100] Between all guns
zrangebyscore guns 30 100 limit 2 1 withscores # 30-100 Between guns Pagination , each page 1 strip , The third page
zrevrangebyscore guns 100 40 # Check the bomb capacity at (40-100] Between all guns
zrevrangebyscore guns 100 30 limit 2 1 withscores # Pagination , each page 1 strip , The third page
zcard guns # Check the number of types of guns in the system
zcount guns (20 50 # obtain (20-50] The number of all guns in the interval
zrank guns dp28 # From small to large , View rankings
zrevrank guns dp28 # From big to small
zscore guns ak47 # Check the bomb capacity
# Change
zincrby guns 20 m247 # to m247 Gun increase 20 bullets
zincrby guns -20 m247 # to dp28 Reduce 20 bullets
zrem guns ak47 ... # Remove elements by string , Can be multiple at the same time
zremrangebyrank guns 1 2 # Rank according to bomb capacity 0-3 Elements in the interval are removed
zremrangebyscore guns 0 40 # The bomb capacity is less than 40 The hair , Delete all
Hash type
Hash It's a string Type of field( Field ) and value( value ) The mapping table , Suitable for storing dictionaries
# Insert When keys and fields exist , Belongs to update
hset key field value # Single
hmset key field1 value1 field2 value2 # Multiple
# increase
hincrby key field number # Increment the integer value of the specified field
# check
hget key field # Specify the value of the field
hgetall key # Get all fields and values
hkeys key # Get all fields
hvals key # Get all values
# Delete
hdel key field1 [field2] # Delete one or more hash fields , Return the number of deletions
List type
Is a simple list of strings
# insert
lpush key val1 val2 # Insert... From the left
rpush key val1 val2 # Insert... From the right
# to update
lset key index val # Modify the value of a subscript
# Delete
lpop key # Delete the first value on the left , And immediately return the value
rpop key # Delete the first value on the right , And immediately return the value
# When the list is empty , Blocked deletion
blpop mylist 10
brpop mylist 10
lrem key count value # The number of deleted items is returned , Delete the specified value
ltrim key start stop # Intercept data
lrange key start stop # Returns the content in the specified interval
llen key # Get the length of the list
2. Project framework
1. Set up the virtual environment
The virtual environment will not pollute the default python Environmental Science
# Creating a virtual environment
python -m venv myvenv
# Activate the virtual environment
myvenv/Scripys/activate

In a virtual environment , Install the package used
pip install -r requirements.txt
2. establish django project
notes :
- Don't put the project in C disc
- The path cannot have Chinese characters
- edition Django 3.2.X
1. establish django project
django-admin startproject Project name
2. Open the project , Configure the created virtual environment


Click on add

appear venv Catalog , It means that the virtual environment is created successfully
How to enter the virtual environment
In the console
cd venv/scripts # Get into scripts Catalog
activate # Activate the virtual environment
How to exit the virtual environment
cd venv/scripts # Get into scripts Catalog
deactivate.bat # Execute the exit command
3. Configure cross domain
1. Install cross domain libraries
pip install django-cors-header
2. Register subapplication
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework', # drf frame
'corsheaders', # Cross domain
'users', # Subapplication
]
3. Register middleware
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware', # Cross domain middleware
]
4. Setting configuration items
# Configure cross domain related configuration items
CORS_ORIGIN_WHITELIST = [ # To configure ip White list
"http://127.0.0.1:8080",
"http://localhost:8080",
"http://127.0.0.1:8000",
]
CORS_ALLOW_CREDENTIALS = True # allow cookie
CORS_ALLOW_METHODS = ("*") # Configure the allowed request methods
CORS_ALLOW_HEADERS = ("*") # Configure the allowed request headers
4. Run front end projects
speak vue Drag the project to a new file , Open the little black box
npm install
function
npm run dev
边栏推荐
- Summary of common commands of vim
- Federated primary keys and indexes
- 面试必备之数据库专题
- C1 -- vivado configuration vs code text editor environment 2022-07-21
- vim常用命令总结
- [Python flask note 5] Blueprint simple à utiliser
- 3.Flask 中的线程
- [监控部署实操]基于granfana展示Prometheus的图表和loki+promtail的图表
- Data Lake: viewing data lake from data warehouse
- 【无标题】
猜你喜欢
![[Hudi]hudi的编译及hudi&spark和hudi&flink的简单使用](/img/6f/e6f5ef79c232d9b27a8334cd8ddaa5.png)
[Hudi]hudi的编译及hudi&spark和hudi&flink的简单使用

Spark常见面试问题整理

Machine learning algorithm for large factory interview (6) time series analysis
![[python flask notes 5] blueprint is easy to use](/img/0a/00b259f42e2fa83d4871263cc5f184.png)
[python flask notes 5] blueprint is easy to use

Getting started with RPC and thrift
![[监控部署实操]基于granfana展示Prometheus的图表和loki+promtail的图表](/img/34/b7a05bff05e1d3a1daef4fb2b98a92.png)
[监控部署实操]基于granfana展示Prometheus的图表和loki+promtail的图表

大厂面试机器学习算法(0):特征工程 | 数据预处理

使用聚类分析 构建信用卡高风险客户识别模型

Activiti工作流使用之新建bpmn文件

MySql语句查询某一级节点的所有子节点
随机推荐
主从同步步骤读写分离+自遇错误分享
JWT header进行编码过程
Usage of countdownlatch
3.Flask 中的线程
MySql语句查询某一级节点的所有子节点
3. Threads in flask
Scattered notes of machine learning: some concepts and notes
Activiti工作流使用之新建bpmn文件
安装企业版pycharm以及anaconda
通用视图,序列化器
Briefly describe the features and application scenarios of redis
混入视图基类
分页、过滤
项目部署(简版)
Oracle创建数据库“监听程序未启动或数据库服务未注册”错误处理
Spectral clustering | Laplace matrix
Mysql-8.0.28 user operation or user permission Operation
人脸识别神经网络实现
idea中复制一个项目/project
sprintboot中使用缓存时候,数据加载不出来