vue項目的創建(路飛前端)
-安裝node.js
-安裝vue的腳手架
-創建vue項目,vue create 項目名字
在pycharm中開發vue
-webstrom,pyacharm,goland,idea,androidStuidio,Php....
-Edit-conf----》點+ 選npm-----》在script對應的框中寫:serve
vue項目的目錄結構
-node_moudules:項目的依賴
-public
-favicon.ico 網頁圖標
-index.html主頁面
-src:
-assets:靜態文件
-compontents:小組件
-views:頁面組件
-App.vue:主組件
-main.js:項目主入口js
-router.js:路由相關,以后配置路由都在這配置
-store.js:vuex相關,狀態管理器
-package.json 項目依賴文件
redis列表操作
conn.lpush('list',*[4,5,6]) #插入列表
# conn.lpushx('list1',3)#只有列表存在時插入右側
# print(conn.llen('list1'))
# print(conn.linsert('list1','AFTER',3,'z'))#在name對應的列表的某一個值前或后插入一個新值,返回值為長度
# conn.lset('list1',0,'f')#對應索引重新賦值
# conn.lpush('list',*[4,5,6])
# conn.lrem('list',2,2) #移除列表內值2開始刪除兩個
# conn.lpop('list') #去除刪除列表最左邊值
# print(conn.lindex('list',1)) 取值
# print(conn.lrange('list',0,2))
# conn.ltrim('list',0,1)#移除不在之間的值
# conn.rpoplpush()#從一個列表去除最右邊元素添加到另一個表左側
# print(conn.blpop(['list','list1'],5))#將多個列表排列,按照從左到右去pop對應列表的元素
# 爬蟲實現簡單分布式:多個url放到列表里,往里不停放URL,程序循環取值,但是只能一台機器運行取值,可以把url放到redis中,多台機器從redis中取值,爬取數據,實現簡單分布式
列表的自定義增量迭代
def l_scan(name,count=1000):
cursor=0
while True:
if cursor>=conn.llen(name):
break
ret=conn.lrange(name,cursor,count)
cursor+=count
for i in ret:
yield i
for i in l_scan('list1',100):
print(i)
字典操作
conn.hmset('dict',{'name':'zzf','age':18})
# print(conn.hmget('dict','name','age'))
# print(conn.hget('dict','name'))
# print(conn.hkeys('dict'))#取key
# print(conn.hvals('dict'))#取values
# print(conn.hgetall('dict'))#慎用
# print(conn.hlen('dict'))
# for i in range(0,10000):
# conn.hmset('dict',{'name%s'%i:'zzf%s'%i})
#z自定義增量迭代
# print(conn.hscan('dict',cursor=0, match=None, count=100))
# for i in conn.hscan_iter('dict',match=None,count=100):
# print(i)
# for i in range(0,10000):
# conn.lpushx('list1',i)
其他常用操作
# print(conn.keys(pattern='*'))
# print(conn.keys(pattern='*a*'))
# print(conn.keys(pattern='?a*'))#模糊匹配key
# print(conn.exists('name'))#是否存在1或者0
# conn.expire('name',10)#設置超時時間
管道
# redis支持5大數據類型,但是它只支持一層
# redis之管道(實現事務)
# 相當於mysql的事務
# pipe = conn.pipeline(transaction=True)
# pipe.multi()
#
# pipe.set('name', 'alex')
# pipe.set('role', 'sb')
#
# pipe.execute()
-第二種方式:
-按裝django-redis
-使用
-在setting中配置:
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"CONNECTION_POOL_KWARGS": {"max_connections": 100}
# "PASSWORD": "123",
}
}
}
-在視圖中使用
from django_redis import get_redis_connection
def test(request):
conn=get_redis_connection()
ret=conn.get('n123')
return HttpResponse('%s'%ret)