redis-server.exe redis.windows.conf
打开另一个cmd窗口,同样使用 cd 命令切换redis安装目录,执行命令启动redis
redis-cli.exe -h 127.0.0.1 -p 6379
pip install redis
import redis
# 建立线程池,避免重复连接
pool = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True)
r = redis.Redis(connection_pool=pool)
def my_demo():
r.set("news1", "http://www.1.com")
r.set("news2", "http://www.2.com")
print(r.get("news1"))
print(r.get("news2"))
if __name__ == '__main__':
my_demo()