BVB Source Codes

rq Show connections.py Source code

Return Download rq: download connections.py Source code - Download rq Source code - Type:.py
  1. # -*- coding: utf-8 -*-
  2. from __future__ import (absolute_import, division, print_function,
  3.                         unicode_literals)
  4.  
  5. from functools import partial
  6.  
  7. from redis import Redis, StrictRedis
  8.  
  9.  
  10. def fix_return_type(func):
  11.     # deliberately no functools.wraps() call here, since the function being
  12.     # wrapped is a partial, which has no module
  13.     def _inner(*args, **kwargs):
  14.         value = func(*args, **kwargs)
  15.         if value is None:
  16.             value = -1
  17.         return value
  18.     return _inner
  19.  
  20.  
  21. PATCHED_METHODS = ['_setex', '_lrem', '_zadd', '_pipeline', '_ttl']
  22.  
  23.  
  24. def _hset(self, key, field_name, value, pipeline=None):
  25.     connection = pipeline if pipeline is not None else self
  26.     connection.hset(key, field_name, value)
  27.  
  28.  
  29. def patch_connection(connection):
  30.     # Don't patch already patches objects
  31.     if all([hasattr(connection, attr) for attr in PATCHED_METHODS]):
  32.         return connection
  33.  
  34.     connection._hset = partial(_hset, connection)
  35.  
  36.     if isinstance(connection, Redis):
  37.         connection._setex = partial(StrictRedis.setex, connection)
  38.         connection._lrem = partial(StrictRedis.lrem, connection)
  39.         connection._zadd = partial(StrictRedis.zadd, connection)
  40.         connection._pipeline = partial(StrictRedis.pipeline, connection)
  41.         connection._ttl = fix_return_type(partial(StrictRedis.ttl, connection))
  42.         if hasattr(connection, 'pttl'):
  43.             connection._pttl = fix_return_type(partial(StrictRedis.pttl, connection))
  44.  
  45.     # add support for mock redis objects
  46.     elif hasattr(connection, 'setex'):
  47.         connection._setex = connection.setex
  48.         connection._lrem = connection.lrem
  49.         connection._zadd = connection.zadd
  50.         connection._pipeline = connection.pipeline
  51.         connection._ttl = connection.ttl
  52.         if hasattr(connection, 'pttl'):
  53.             connection._pttl = connection.pttl
  54.     else:
  55.         raise ValueError('Unanticipated connection type: {}. Please report this.'.format(type(connection)))
  56.  
  57.     return connection
  58.  
downloadconnections.py Source code - Download rq Source code
Related Source Codes/Software:
amazon-dsstne - Deep Scalable Sparse Tensor Network Engine (DSSTNE... 2017-01-08
webpack-demos - a collection of simple demos of Webpack 2017-01-08
Squire - HTML5 rich text editor. Try the demo integration a... 2017-01-08
thor - Thor is a toolkit for building powerful command-li... 2017-01-08
glide - Package Management for Golang h... 2017-01-08
emmet-vim - emmet for vim: http://emmet.io/ ... 2017-01-08
prose - A Content Editor for GitHub. ht... 2017-01-08
sshrc - ring your .bashrc, .vimrc, etc. with you when you ... 2017-01-08
typed.js - A jQuery typing animation script. ... 2017-01-08
find - High-precision indoor positioning framework for mo... 2017-01-08
discover-flask - Full Stack Web Development with Flask. ... 2017-01-12
spring-mvc-showcase - Demonstrates the features of the Spring MVC web fr... 2017-01-12
tushare - TuShare is a utility for crawling historical data ... 2017-01-12
raml-spec - RAML Specification http://raml.... 2017-01-12
android-stackblur - Android StackBlur is a library that can perform a ... 2017-01-12
sound-redux - A Soundcloud client built with React / Redux ... 2017-01-12
httpstat - curl statistics made simple 2017-01-12
vim - Vim configuration file and plug-ins 2017-01-12
appframework - The definitive HTML5 mobile javascript framework ... 2017-01-12
BaiduExporter - Assistant for Baidu to export download links to ar... 2017-01-11

 Back to top