redis.connection — redis-py 2.10.5 documentation http://redis-py.readthedocs.io/en/latest/_modules/redis/connection.html#ConnectionPool

实例化后 应关闭所有连接,或者 释放该连接,避免 端口号被耗尽

from redis import *
redis_key = ['192.168.3.212', '6379', 'nfwt&2016', 4]
def return_redis(redis_key):
REDIS_HOST, REDIS_PORT, PASSWORD, db = redis_key
rds = Redis(host=REDIS_HOST, port=REDIS_PORT, password=PASSWORD, db=db)
return rds
rds = return_redis(redis_key)

这叫我想起来之前遇到过的数据库连接未释放的问题了,关注生命周期是关键
2
est 150 天前 ♥ 1
redis-py 真是想各种吐槽

- 连接池不能负载均衡
- 连接池不能读写分离
- zadd 不支持 nx 等参数
- zadd 那个坑死无数新人的参数顺序。
3
lolizeppelin 150 天前 via Android
你们用都不看源码的么 那个链接池简陋得连心跳都没 你们也直接用
4
geew 150 天前
@lolizeppelin #3 源码看了 确实简陋 有别的选择吗 基本都在用这个库的吧
5
geew 150 天前
@est #2 确实 有更好的库可以选择吗
6
lolizeppelin 150 天前 via Android
当然自己重新封装 自己写心跳啊
7
swulling 150 天前
https://github.com/andymccurdy/redis-py/pulls

吐槽不如提 Pull Request 就好了
8
swulling 150 天前
如果发现已经有 Pull Request,+1 求合并就好了,求合并的人多了,自然受重视

如果只是默默吐槽,那就不怪别人了
9
lolizeppelin 150 天前 via Android
没用的 对比下 kombu 的代码 就知道了 这玩意就是个基本接口根本没打算做全功能

就算是 kombu openstack 还再封装过一遍

        return self.execute_command(command, *pieces, **kwargs)

[docs]class Redis(StrictRedis):
"""
Provides backwards compatibility with older versions of redis-py that
changed arguments to some commands to be more Pythonic, sane, or by
accident.
""" # Overridden callbacks
RESPONSE_CALLBACKS = dict_merge(
StrictRedis.RESPONSE_CALLBACKS,
{
'TTL': lambda r: r >= 0 and r or None,
'PTTL': lambda r: r >= 0 and r or None,
}
) [docs] def pipeline(self, transaction=True, shard_hint=None):
"""
Return a new pipeline object that can queue multiple commands for
later execution. ``transaction`` indicates whether all commands
should be executed atomically. Apart from making a group of operations
atomic, pipelines are useful for reducing the back-and-forth overhead
between the client and server.
"""
return Pipeline(
self.connection_pool,
self.response_callbacks,
transaction,
shard_hint) [docs] def setex(self, name, value, time):
"""
Set the value of key ``name`` to ``value`` that expires in ``time``
seconds. ``time`` can be represented by an integer or a Python
timedelta object.
"""
if isinstance(time, datetime.timedelta):
time = time.seconds + time.days * 24 * 3600
return self.execute_command('SETEX', name, time, value) [docs] def lrem(self, name, value, num=0):
"""
Remove the first ``num`` occurrences of elements equal to ``value``
from the list stored at ``name``. The ``num`` argument influences the operation in the following ways:
num > 0: Remove elements equal to value moving from head to tail.
num < 0: Remove elements equal to value moving from tail to head.
num = 0: Remove all elements equal to value.
"""
return self.execute_command('LREM', name, num, value) [docs] def zadd(self, name, *args, **kwargs):
"""
NOTE: The order of arguments differs from that of the official ZADD
command. For backwards compatability, this method accepts arguments
in the form of name1, score1, name2, score2, while the official Redis
documents expects score1, name1, score2, name2. If you're looking to use the standard syntax, consider using the
StrictRedis class. See the API Reference section of the docs for more
information. Set any number of element-name, score pairs to the key ``name``. Pairs
can be specified in two ways: As *args, in the form of: name1, score1, name2, score2, ...
or as **kwargs, in the form of: name1=score1, name2=score2, ... The following example would add four values to the 'my-key' key:
redis.zadd('my-key', 'name1', 1.1, 'name2', 2.2, name3=3.3, name4=4.4)
"""
pieces = []
if args:
if len(args) % 2 != 0:
raise RedisError("ZADD requires an equal number of "
"values and scores")
pieces.extend(reversed(args))
for pair in iteritems(kwargs):
pieces.append(pair[1])
pieces.append(pair[0])
return self.execute_command('ZADD', name, *pieces) class PubSub(object):

  


Source code for redis.connection的更多相关文章

  1. Memcached source code analysis (threading model)--reference

    Look under the start memcahced threading process memcached multi-threaded mainly by instantiating mu ...

  2. DevExpress Components16.2.6 Source Code 编译

    DevExpress 是一个比较有名的界面控件套件,提供了一系列优秀的界面控件.这篇文章将展示如何在拥有源代码的情况下,对 DevExpress 的程序集进行重新编译. 特别提示:重编译后,已安装好的 ...

  3. DevExpress Components16.2.6 Source Code 重编译教程

    DevExpress 是一个比较有名的界面控件套件,提供了一系列优秀的界面控件.这篇文章将展示如何在拥有源代码的情况下,对 DevExpress 的程序集进行重新编译. 特别提示:重编译后,已安装好的 ...

  4. Tips for newbie to read source code

    This post is first posted on my WeChat public account: GeekArtT Reading source code is always one bi ...

  5. Data source rejected establishment of connection, message from server: "Too many connections"解决办法

    异常名称 //数据源拒绝从服务器建立连接.消息:"连接太多" com.MySQL.jdbc.exceptions.jdbc4.MySQLNonTransientConnection ...

  6. 编程等宽字体Source Code Pro(转)

    Source Code Pro - 最佳的免费编程字体之一!来自 Adobe 公司的开源等宽字体下载     每一位程序员都有一套自己喜爱的代码编辑器与编程字体,譬如我们之前就推荐过一款"神 ...

  7. How to build the Robotics Library from source code on Windows

    The Robotics Library is an open source C++ library for robot kinematics, motion planning and control ...

  8. How to build windows azure PowerShell Source Code

    Download any version source code of Windows Azure Powershell from https://github.com/Azure/azure-sdk ...

  9. akka cluster sharding source code 学习 (1/5) 替身模式

    为了使一个项目支持集群,自己学习使用了 akka cluster 并在项目中实施了,从此,生活就变得有些痛苦.再配上 apache 做反向代理和负载均衡,debug 起来不要太酸爽.直到现在,我还对 ...

随机推荐

  1. LeetCode(10) Regular Expression Matching

    题目 Implement regular expression matching with support for '.' and '*'. '.' Matches any single charac ...

  2. python3--算法基础:二分查找/折半查找

    算法基础:二分查找/折半查找 #!/usr/bin/env python # -*- coding:utf-8 -*- # 算法基础:二分查找/折半查找 def binarySearch(dataSo ...

  3. Python 迭代器&生成器,装饰器,递归,算法基础:二分查找、二维数组转换,正则表达式,作业:计算器开发

    本节大纲 迭代器&生成器 装饰器  基本装饰器 多参数装饰器 递归 算法基础:二分查找.二维数组转换 正则表达式 常用模块学习 作业:计算器开发 实现加减乘除及拓号优先级解析 用户输入 1 - ...

  4. Flask--修改默认的static文件夹的方法

    修改的flask默认的static文件夹只需要在创建Flask实例的时候,把static_folder和static_url_path参数设置为空字符串即可. app = Flask(__name__ ...

  5. BGP路由属性详解

    Weight属性:cisco私有的BGP属性参数,它只适用于一台路由器中的路由,也就是不会传递给任何其他的路由器.他的取值范围为<0-65535>,这个数越大优先级越高,默认从邻居学到的路 ...

  6. [luoguP2129] L国的战斗续之多路出击(模拟 || 矩阵)

    传送门 1.模拟 easy #include <cstdio> #define N 500001 int n, m; int X[N], Y[N], x[N], y[N], a = 1, ...

  7. 【枚举】Southwestern Europe Regional Contest H - Sheldon Numbers

    https://vjudge.net/contest/174235#problem/H [题意] 求[x,y]之间有多少个Sheldon Number Sheldon Number是二进制满足以下条件 ...

  8. Couriers(bzoj 3524)

    Description 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0. ...

  9. Android操作系统架构

    Android操作系统架构   Android操作系统整体应用架构 Android系统架构和一些普遍的操作系统差不多,都是采用了分层的架构,从他们之间的架构图看,Android系统架构分为四个层,从高 ...

  10. linux 常见名词及命令(二)

    pwd 用于显示当前的工作目录. cd 用于切换工作路径 cd - 切换到上一次的目录 cd ~ 切换到家目录 cd ~username 切换到其他用户的家目录 cd .. 切换到上级目录 ls 用于 ...