当前位置:网站首页>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
边栏推荐
- 2. Analysis of the return value of the startup function
- Machine learning algorithm for large factory interview (6) time series analysis
- 【无标题】
- 3.Flask 中的线程
- Usage of countdownlatch
- 图片模糊处理批量生产模糊数据集
- [Anaconda environmental management and package management]
- 初识Flask
- When using cache in sprintboot, the data cannot be loaded
- pyspark学习笔记
猜你喜欢
随机推荐
With only 5000 lines of code, AI renders 100 million landscape paintings on v853
CountDownLatch的用法
Dictionary creation and copying
MySQL statement queries all child nodes of a level node
Sorting out common SQL interview questions and answers
Xssgame games (XSS learning) level1-15
Mysql-8.0.28 user operation or user permission Operation
Flask源码剖析(一)请求入口
How to merge the website content with video and audio separated? How to write batch download code?
After the formula in word in WPS is copied, there is a picture
Redis数据库和项目框架
Pywinauto+某应用程序(学习至第9讲)--受阻
The super simple face recognition API can realize face recognition in just a few lines of code
【无标题】
通用视图,序列化器
pycharm占用c盘
【无标题】
Activiti工作流使用之Activiti-app的安装及流程创建
Usage of countdownlatch
Mysql事务回滚机制与原理









