1.python想操作redis,需要安裝第三方模塊(我是在windows下進行操作的)
pip install redis
2.連接數據庫
#coding:utf-8
import
redis
r
=
redis.Redis(host
=
'127.0.0.1'
, port
=
6379
)#host后的IP是需要連接的ip,本地是127.0.0.1或者localhost
r.
set
(
'name'
,
'test'
)
print
(r.get(
'name'
))
# 輸出結果
b
'test'