close

undefined

以下紀錄如何使用 Python 安裝 Redis 與使用 Redis,使用的IDEPyCharm

Step 1: 先去https://github.com/MicrosoftArchive/redis/releases 來抓 Redis:

r_1.jpg

 

Step 2: 將抓下來的檔案解壓縮,解壓縮後,到該資料夾並且進到CMD模式:

r_2.jpg

 

輸入下列指令:

redis-server.exe redis.windows.conf

r_3.jpg

 

這時候伺服器已經開啟。

 

Step 3: 使用 PyCharm 來安裝 Redis,如果不曉得怎安裝可以參考下述連結:

http://xken831.pixnet.net/blog/post/462988406-%5b

r_4.jpg

 

Step 4: 接著使用下述的連接方式來呼叫 redis:

#使用 redis 模組
import redis

#host是主機名稱, 預設port為6379
r = redis.Redis(host='localhost', port=6379, decode_responses=True)

#set(key, value)
#
存入Key為 Ken, Value 為 Test
r.set('Ken', 'Test')

#用list方式取得Key為Ken的值
print(r['Ken'])
print(r.get('Ken'))  # 取出键name对应的值
print(type(r.get('Ken')))

 

執行結果:

Test

Test

<class 'str'>

 

 

[Reference]

  1. http://www.runoob.com/redis/redis-install.html
  2. https://www.jianshu.com/p/2639549bedc8
arrow
arrow
    全站熱搜

    葛瑞斯肯 發表在 痞客邦 留言(0) 人氣()