首页 技术 正文
技术 2022年11月14日
0 收藏 618 点赞 2,421 浏览 3255 个字

python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法
window安装redis,下载Redis的压缩包
https://github.com/dmajkic/redis/downloads
如redis-2.4.5-win32-win64.zip
下载完后将其解压放在自己要放的目录下
如果你是32位的话就进32bit的文件夹,64位就进64bit文件夹

文件夹进去后会看到几个文件:
redis-benchmark.exe: 性能测试 模拟N个客户端发送set,get请求
redis-check-aof.exe:更新日志检查
redis-check-dump.exe:本地数据库检查
redis-server.exe:服务程序

打开dos命令栏,进入到redis的目录下面(如D:\redis),输入以下命令:
C:\Users\Administrator>d:
D:\>cd redis

D:\redis>redis-server.exe redis.conf
[5184] 22 Jul 15:53:53 * Server started, Redis version 2.4.5
[5184] 22 Jul 15:53:53 * DB loaded from disk: 0 seconds
[5184] 22 Jul 15:53:53 * The server is now ready to accept connections on port 6
379
启动成功(注:不需要安装,关闭命令栏就相当于关闭redis服务了,下次启动需要重新执行上面命令)

然后再打开一个dos命令栏,进入到redis的目录下,输入以下命令:
D:\redis>redis-cli.exe -h 127.0.0.1 -p 6379
进入到redis环境,测试一下set get命令:

redis 127.0.0.1:6379> set zdz helloredis
OK
redis 127.0.0.1:6379> get zdz
“helloredis”
redis 127.0.0.1:6379> set arr “{‘aa’:1122,’bb’:444}”
OK
redis 127.0.0.1:6379> keys *
1) “zdz”
2) “arr”
——————————–
set key value 存值
get key 取值
=========================================
#redis_class.py
import redis,json
class Credis(object):
def __init__(self):
self.pool = redis.ConnectionPool(host=’localhost’, port=6379, db=0, socket_timeout=4)

def setRedis(self,key, err, status, msg):
result = redis.Redis(connection_pool=self.pool)
redisValue = {‘err’:err,’status’:status,’msg’:msg}
redisValue = json.dumps(redisValue)
return result.set(key,redisValue)

def getRedis(self,key):
result = redis.Redis(connection_pool=self.pool)
return result.get(key)

credis = Credis()
使用例子:
from redis_class import credis
credis.setRedis(‘key’,0,1,’set’)
=========================================
Parser安装
Parser可以控制如何解析redis响应的内容。redis-py包含两个Parser类,PythonParser和HiredisParser。默认,如果已经安装了hiredis模块,redis-py会使用HiredisParser,否则会使用PythonParser。
HiredisParser是C编写的,由redis核心团队维护,性能要比PythonParser提高10倍以上,所以推荐使用。

使用easy_install命令安装:easy_install hiredis

=========================================
pycharm 增加 redis 支持
用pip安装redis比较顺利
D:\Python27>pip install redis
让pycharm ide上支持import redis不报错的方法:
在pycharm里 File -> Settings -> Python interpreter
进入到Python interpreter 点击+按钮 搜索redis 选择一个安装就可以了。

使用python+redis实现实时聊天室–pythoner.org
http://pythoner.org/wiki/701/

===========================================
安装MySQL-python报错比较多,但不关mysql的事
Windows下安装MySQLdb遇到的问题及解决方法
>pip install MySQL-python
error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat).
Get it from http://aka.ms/vcpython27
—————————————-
按上面提示到http://aka.ms/vcpython27下载安装后执行VCForPython27.msi后仍然报下面的错误:
_mysql.c(42) : fatal error C1083: Cannot open include file: ‘config-win.h’:
No such file or directory
error: command ‘C:\\Users\\Administrator\\AppData\\Local\\Programs\\Common\\
Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe’ failed with exit
status 2
—————————————
解决办法:搜索或者到下面网址下载安装:MySQL-python-1.2.3.win-amd64-py2.7.exe

MySQL-python 1.2.3 for Windows and Python 2.7, 32bit and 64bit versions | codegood
http://www.codegood.com/archives/129

安装后再用pip命令提示已经安装了
C:\Users\Administrator>pip install MySQL-python
Requirement already satisfied (use –upgrade to upgrade): MySQL-python in d:\pyt
hon27\lib\site-packages

在pycharm里 File -> Settings -> Python interpreter 里面添加MySQL-python就可以了

=======================================

下面是设置的截图:

python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法

使用实例代码请看本人另外一篇博客:

python3.4学习笔记(二十五) Python 调用mysql redis实例代码 – 流风,飘然的风 – 博客园
http://www.cnblogs.com/zdz8207/p/python_learn_note_25.html

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295