window怎么运行python系python连接linux服务器上Redis

Redis进阶实践之六Redis Desktop Manager连接Windows和Linux系统上的Redis服务
Redis进阶实践之六Redis Desktop Manager连接Windows和Linux系统上的Redis服务
原文:Redis进阶实践之六Redis Desktop Manager连接Windows和Linux系统上的Redis服务
今天本来没有打算写这篇文章,但是,今天测试Redis的时候发现了两个问题,第一个问题是:Redis Desktop Manager无法连接虚拟机上Linux...
今天本来没有打算写这篇文章,但是,今天测试Redis的时候发现了两个问题,第一个问题是:Redis Desktop Manager无法连接虚拟机上Linux系统上的Redis服务,第二个问题是:我本地有2个版本的Redis服务,一个是Windows版本的Redis服务,另一个版本是Linux版本的Redis服务,Linux系统上的Redis可以连接Windows系统上的Redis服务,但是Windows系统上的Redis不能访问Linux系统上的Redis服务。其实这两个问题都是由于一个原因引起的,那就是虚拟机上的Linux系统的6379端口号没开启导致的,对于第一次使用redis的情况来说,可能就是毁灭性的。我解决了这些问题,把解决过程记录下来,也是为了给第一次使用Redis的程序员们提提醒,也为自己以后查询方便。使用Redis Desktop Manager连接Window下的Redis服务很简单,没什么可说的。如果大家要想下载Redis Desktop Manager 工具,可以去它的官网下载,地址如下: ,当然,可以有其他的管理Redis的可视化工具,那就是Redis Studio,去百度上可以直接下载。话不多说,我们进入正题吧。
二、安装和问题解决
1、我们先去官网下载Redis Desktop Mananger工具,这个工具是可视化的,可以很好的管理Redis服务,操作各种命令。很方便和简单。
2、下载下来,双击文件运行,安装文件。此步直接点击【下一步】。
3、在该步,我们同意协议,继续安装,点击【I Agree(同意)】,继续安装步骤。
4、在该步,选择要安装文件的目录,然后点击【Install (安装)】,继续安装步骤。
5、在此步,我们可以看到安装的进度,等待安装完成。
6、安装完成,我们继续点击【Next(下一步)】,继续安装步骤。
7、安装完成,点击【Finish(完成)】,并选择【Run Redis Desktop Manager】选项。
8、我们开始使用Redis Desktop Manager工具连接Redis服务。点击左下角的【connect
to redis server】按钮,开始连接redis服务。
9、打开连接窗口,该窗口有四个可以选择的连接窗口,我们默认选择第一种,就是【Connection】,其他窗口如下:
该窗口输入的参数是连接Windows系统上的Redis服务,直接输入【Name(名称)】,【Host(服务器)】和端口号【Port(端口号)】,如果有密码,需要在【Auth】输入栏输入密码,没有就为空,然后点击【Test Connection(测试连接)】,弹出测试成功的窗口,点击【OK(确定)】。然后点击【Connection(连接)】窗口的【OK(确定)】按钮,连接成功。
SSH Tunnel窗口:
Advanced Settings窗口:
10、正在连接Redis服务器
11、然后我们按着同样的方法,连接Linux系统上的Redis服务的时候出现失败。我们要解决问题,有几个操作要确定,操作步骤如下:
11.1】第一步,我们要确定Redis的配置文件Redis.conf里面的bind项目的值是我们Linux系统的IP地址,不是默认的127.0.0.1.
//执行命令如下
192.168.127.128:6379&ifconfig
//会显示系统的ip地址信息
192.168.127.128:6379&config get bind
2)"192.168.127.128"
11.2】、如果上一步正常,获取Linux的IP地址,然后在Windows系统下,打开cmd窗口,执行一下命令 telnet 192.168.127.128 6379,如果测试连接失败,说明CentOS的6379端口没有开启
telnet 192.168.127.128 6379
如果telnet命令无效,提示“telnet不是内部或外部命令”,你需要去【控制面板】,打开【程序和功能】,然后打开【启动和关闭Windows功能】窗口,在窗口滑动列表,找到【telnet客户端】选项,然后选择该项,Window系统会安装对telnet命的支持。
11.3】、开启端口,让我们回到虚拟机,执行以下命令来开启端口。
[root@linux~]#firewall-cmd --query-port=6379/tcp
[root@linux~]#firewall-cmd --add-port=6379/tcp
[root@linux~]#firewall-cmd --query-port=6379/tcp
//输入firewall-cmd --query-port=6379/tcp,如果返回结果为no,那么证明6379端口确实没有开启。
//输入firewall-cmd --add-port=6379/tcp,将6379端口开启,返回success。
//然后再执行上一条命令,返回yes,证明端口已经成功开启。
//由于linux防火墙默认开启,redis的服务端口6379并不在开放规则之内,所有需要将此端口开放访问或者关闭防火墙。
//关闭防火墙命令:sevice iptables stop
//如果是修改防火墙规则,可以修改:/etc/sysconfig/iptables文件
//再用Telnet 测.返回的结果一片纯黑,ok了
在Linux系统上执行开启端口命令:
11.4】、所有操作完成后,Linux系统上的Redis可以连接成功了。
11.5】、Windows和Linux系统上的Redis 连接成功,效果如图。
12、完成以上操作,所有工作完成。
今天解决了一个问题,感觉很好,只有自己亲身走一遍,才可以了解更清楚,道听途说,是不靠谱的。当然redis的可视化管理工具,并不是只有redis desktop manager,在此,我在向大家推荐一款redis图形化操作的客户端Redis Studio,比Redis Desktop Manager好用太多,可以查看运行情况、查看数据和类型、查看剩余有效时间、刷新数据、删除数据,甚至可以直接在图形界面配置redis,再也不用去配置文件里懵逼了。虽然我们有了好的工具,但是基本功还是不能忘记的。好了,今天就到这里了,但是努力还要继续,下一篇文章介绍一下lua脚本,
用云栖社区APP,舒服~
【云栖快讯】《阿里巴巴Java开发手册》(详尽版)已经上线!您的Java学好了吗?如果没有,那就赶紧加入学习吧!&&
文章8365篇
一种稳定可靠、性能卓越、可弹性伸缩的数据库服务。基于飞天分布式系统和全SSD盘高性能存储,支...
支持MySQL、SQL Server、PostgreSQL、MongoDB、Redis等关系...
是阿里云安全专家基于阿里云多年安全最佳实践经验为云上用户提供的全方位安全技术和咨询服务,为云...
为您提供简单高效、处理能力可弹性伸缩的计算服务,帮助您快速构建更稳定、安全的应用,提升运维效...
飞天发布会第8期:智能选址解决方案没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!Python连接Redis
1、安装Redis的Python包 使用easy-install安装,关于easy-install的配置,参考: http://www.linuxeye.com/Linux/1789.html [root@biao ~]# easy_install2.7.3 redisSearching for redisReading http://pypi.python.org/simple/redis
1、安装Redis的Python包
使用easy-install安装,关于easy-install的配置,参考:
[root@biao ~]# easy_install2.7.3 redis
Searching for redis
Reading http://pypi.python.org/simple/redis/
Reading http://github.com/andymccurdy/redis-py
Best match: redis 2.7.2
Downloading http://pypi.python.org/packages/source/r/redis/redis-2.7.2.tar.gz#md5=17ac60dcf13eb33f82cc2
Processing redis-2.7.2.tar.gz
Running redis-2.7.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Y85sxR/redis-2.7.2/egg-dist-tmp-z3jKjB
zip_ analyzing archive contents...
Adding redis 2.7.2 to easy-install.pth file
Installed /usr/local/python2.7.3/lib/python2.7/site-packages/redis-2.7.2-py2.7.egg
Processing dependencies for redis
Finished processing dependencies for redis
可以在相应目录下检查是否安装成功,easy-install安装的扩展包默认在python的site-packages目录下:
[root@biao ~]# whereis python2.7.3
python2.7: /bin/python2.7.3 /usr/local/python2.7.3
[root@biao ~]# cd /usr/local/python2.7.3/lib/python2.7/site-packages/
[root@biao site-packages]# ll
-rwxrwxrwx 1 root root
310 Jan 10 01:34 easy-install.pth
drwxrwxr-x 2 grid grid
4096 Dec 11 21:09 hbase
drwxrwxrwx 4 root root
5 19:05 numpy-1.6.2-py2.7-linux-i686.egg
drwxr-xr-x 2
4096 Nov 28
2011 python-memcached-1.48
-rwxr-xr-x 1 root root
40448 Dec 29 00:13 python-memcached-1.48.tar.gz
-rwxrwxrwx 1 root root
5 18:02 README
-rw-r--r-- 1 root root
60370 Jan 10 01:34 redis-2.7.2-py2.7.egg
-rwxrwxrwx 1 root root 331999 Dec
5 18:29 setuptools-0.6c11-py2.7.egg
-rwxrwxrwx 1 root root
5 18:29 setuptools.pth
-rw-rw-r-- 1 grid grid 156642 Dec 11 20:57 thrift-0.9.0-py2.7-linux-i686.egg
OK,redis-2.7.2-py2.7.egg就是我们需要的。
root@biao ~]# python2.7.3
Python 2.7.3 (default, Dec
[GCC 4.1.2
(Red Hat 4.1.2-44)] on linux2
Type &help&, &copyright&, &credits& or &license& for more information.
&&& import redis
&&& redisClient=redis.StrictRedis(host='127.0.0.1',port=6379,db=0)
&&& redisClient.set('test_redis','Hello Python')
&&& value=redisClient.get('test_redis')
&&& print value
Hello Python
&&& redisClient.delete('test_redis')
&&& value=redisClient.get('test_redis')
&&& print value
如上所示,Python连接Redis成本,能正常操作。
Python就是简单,方便简洁。更多方法以后再试
&&& dir(redis)
['AuthenticationError', 'Connection', 'ConnectionError', 'ConnectionPool', 'DataError', 'InvalidResponse', 'PubSubError', 'Redis', 'RedisError', 'ResponseError', 'StrictRedis', 'UnixDomainSocketConnection', 'VERSION', 'WatchError', '__all__', '__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__version__', '_compat', 'client', 'connection', 'exceptions', 'from_url', 'utils']
&&& redisClient=redis.StrictRedis(host='127.0.0.1',port=6379,db=0)
&&& dir(redisClient)
['RESPONSE_CALLBACKS', '__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_zaggregate', 'append', 'bgrewriteaof', 'bgsave', 'bitcount', 'bitop', 'blpop', 'brpop', 'brpoplpush', 'client_kill', 'client_list', 'config_get', 'config_set', 'connection_pool', 'dbsize', 'debug_object', 'decr', 'delete', 'echo', 'eval', 'evalsha', 'execute_command', 'exists', 'expire', 'expireat', 'flushall', 'flushdb', 'from_url', 'get', 'getbit', 'getrange', 'getset', 'hdel', 'hexists', 'hget', 'hgetall', 'hincrby', 'hincrbyfloat', 'hkeys', 'hlen', 'hmget', 'hmset', 'hset', 'hsetnx', 'hvals', 'incr', 'incrbyfloat', 'info', 'keys', 'lastsave', 'lindex', 'linsert', 'llen', 'lock', 'lpop', 'lpush', 'lpushx', 'lrange', 'lrem', 'lset', 'ltrim', 'mget', 'move', 'mset', 'msetnx', 'object', 'parse_response', 'persist', 'pexpire', 'pexpireat', 'ping', 'pipeline', 'pttl', 'publish', 'pubsub', 'randomkey', 'register_script', 'rename', 'renamenx', 'response_callbacks', 'rpop', 'rpoplpush', 'rpush', 'rpushx', 'sadd', 'save', 'scard', 'script_exists', 'script_flush', 'script_kill', 'script_load', 'sdiff', 'sdiffstore', 'set', 'set_response_callback', 'setbit', 'setex', 'setnx', 'setrange', 'shutdown', 'sinter', 'sinterstore', 'sismember', 'slaveof', 'smembers', 'smove', 'sort', 'spop', 'srandmember', 'srem', 'strlen', 'substr', 'sunion', 'sunionstore', 'time', 'transaction', 'ttl', 'type', 'unwatch', 'watch', 'zadd', 'zcard', 'zcount', 'zincrby', 'zinterstore', 'zrange', 'zrangebyscore', 'zrank', 'zrem', 'zremrangebyrank', 'zremrangebyscore', 'zrevrange', 'zrevrangebyscore', 'zrevrank', 'zscore', 'zunionstore']
关于更多redis-Python详细介绍,可以参考作者的提供的资料:
转载请保留固定链接:
------分隔线----------------------------
fail2ban是由Python语言开发监控软件,通过监控系统日志(Debian/...
Linux在4.9版本的内核新增了一款TCP拥塞控制技术:BBR, Linode 最新...
概述 RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支...
概述 RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支...
一、使用背景 当生产环境有很多服务器、很多业务模块的日志需...
What is the opcode cache? When the interpreter to complete the analysis of script...net 搭建分布式框架(二)Windows 下的.net 连接 Linux 下的 Redis
时间: 11:12:37
&&&& 阅读:32
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&接着上节讲
一、修改reids配置文件
// 修改reids配置文件中的ip
bind 127.0.0.1 改成 0.0.0.0
vi /etc/redis/<span style="color: #79.conf
// 关闭redis 服务
service redisd stop
//重启redis 服务 注意:如果用 service redisd start 启动可能会有问题,所以用如下命令启动
redis-server /etc/redis/<span style="color: #79.conf &
二、防火墙端口设置
//开放6379端口
firewall-cmd --zone=public --add-port=<span style="color: #79/tcp --permanent
//查看已经开放的端口
firewall-cmd --list-ports
//重启防火墙
firewall-cmd --reload
三、安装redis desktop manager管理工具测试
下载地址:https://redisdesktop.com/download
选择 连接到redis服务器 ,在输入ip地址,然后点击测试连接,成功后输入连接名后点确定
四、打开Visual Studio 选择 文件——新建——项目 弹出窗口中选择 控制台应用
五、在新建的项目上右键选择管理NuGet程序包 安装&StackExchange.Redis&
六、新建一个类 RedisHelper.cs ,然后在main方法中调用 最后按 F5 运行程序
using System.Collections.G
using System.L
using System.T
using System.Threading.T
using StackExchange.R
namespace ConsoleApp2
class RedisHelper
static ConfigurationOptions configuration = ConfigurationOptions.Parse("<span style="color: #2.168.1.11:6379");
private static readonly Object Locker = new object();
private static ConnectionMultiplexer redisC
public static ConnectionMultiplexer getRedisConn()
if (redisConn == null)
lock (Locker)
if (redisConn == null || !redisConn.IsConnected)
redisConn = ConnectionMultiplexer.Connect(configuration);
return redisC
using System.Collections.G
using System.L
using System.T
using System.Threading.T
namespace ConsoleApp2
class Program
static void Main(string[] args)
var redisConn = RedisHelper.getRedisConn();
var db = redisConn.GetDatabase();
bool result = db.StringSet("name","我是刘明君");
Console.WriteLine(result);
Console.Read();
&标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&原文:https://www.cnblogs.com/liumingjun100/p/8972809.html
教程昨日排行
&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!

我要回帖

更多关于 window怎么运行python 的文章

 

随机推荐