1、redis連線
redis連線例項是執行緒安全的,可以直接將redis連線例項設定為乙個全域性變數,直接使用。
安裝:pip install redis
2、連線池import redis
r = redis.redis(host=
'licalhost'
,port=
6379
,decode_responses=
true)r.
set(
'student'
,'jiexi'
(r.get(
'student'
))
redis-py使用connection pool來管理對乙個redis server的所有連線,避免每次建立、釋放連線的開銷。預設,每個redis例項都會維護乙個自己的連線池。
import redis
pool = redis.connectionpool(host=
'licalhost'
,port=
6379
,decode_responses=
true
)r = redis.redis(connection_pool = pool)
r.set
('student'
,'lisa'
(r.get(
'student'
))
python正則re使用
1 import re 將正規表示式編譯成pattern物件 pattern re.compile r hello re.i 使用pattern匹配文字,獲得匹配結果,無法匹配時將返回none match pattern.match hello world if match 使用match獲得分組資...
python基礎 re使用
以乙個帶檔案操作的例子說明 目標 開啟乙個檔案,提取 中的內容,儲存在乙個新的檔案裡 涉及到的一些操作 序號操作 1檔案操作codecs.open 2正規表示式re模組的使用 上 import linecache import re import codecs filename lolstatist...
python中re模組的使用
res re.match pattern,string,flags 0 字串的開頭是否能匹配正規表示式。返回 sre.sre match物件,如果 不能匹配返回none。如果匹配的話,res.string可以獲得原始的字串,並不是匹配的字串 re.sub pattern,repl,string,co...