Return a conn object for accessing memcached
339853
def get_conn(opts, profile=None, host=None, port=None):
    '''
    
    '''
    if not (host and port):
        opts_pillar = opts.get('pillar', {})
        opts_master = opts_pillar.get('master', {})

        opts_merged = {}
        opts_merged.update(opts_master)
        opts_merged.update(opts_pillar)
        opts_merged.update(opts)

        if profile:
            conf = opts_merged.get(profile, {})
        else:
            conf = opts_merged

        host = conf.get('memcached.host', DEFAULT_HOST)
        port = conf.get('memcached.port', DEFAULT_PORT)

    if not six.text_type(port).isdigit():
        raise SaltInvocationError('port must be an integer')

    if HAS_LIBS:
        return memcache.Client(['{0}:{1}'.format(host, port)])
    else:
        raise CommandExecutionError(
            '(unable to import memcache, '
            'module most likely not installed)'
        )
1323742
def _get_conn(socket=DEFAULT_SOCKET_URL):
    '''
    
    '''
    assert os.path.exists(socket), '{0} does not exist.'.format(socket)
    issock = os.stat(socket).st_mode
    assert stat.S_ISSOCK(issock), '{0} is not a socket.'.format(socket)
    ha_conn = haproxy.conn.HaPConn(socket)
    return ha_conn
173845
def get(self, conn, key, default=None):
        
        values, _ = yield from self._multi_get(conn, key)
        return values.get(key, default)
26248
def get_key(key, host=None, port=None, db=None, password=None):
    '''
    
    '''
    server = _connect(host, port, db, password)
    return server.get(key)
1325261
def server(self):
        """"""

        conn = self.connection_class(self)
        with self.mutex:
            self.connections.append(conn)
        return conn
364677
function readcache($filename, &$err, $secs2cache, $rsClass)
		{
			$false = false;
			if (!$this->_connected) $this->connect($err);
			if (!$this->_memcache) return $false;

			$rs = $this->_memcache->get($filename);
			if (!$rs) {
				$err = 'Item with such key doesn\'t exists on the memcached server.';
				return $false;
			}

			// hack, should actually use _csv2rs
			$rs = explode("\n", $rs);
            unset($rs[0]);
            $rs = join("\n", $rs);
 			$rs = unserialize($rs);
			if (! is_object($rs)) {
				$err = 'Unable to unserialize $rs';
				return $false;
			}
			if ($rs->timeCreated == 0) return $rs; // apparently have been reports that timeCreated was set to 0 somewhere

			$tdiff = intval($rs->timeCreated+$secs2cache - time());
			if ($tdiff <= 2) {
				switch($tdiff) {
					case 2:
						if ((rand() & 15) == 0) {
							$err = "Timeout 2";
							return $false;
						}
						break;
					case 1:
						if ((rand() & 3) == 0) {
							$err = "Timeout 1";
							return $false;
						}
						break;
					default:
						$err = "Timeout 0";
						return $false;
				}
			}
			return $rs;
		}
1067116
def get_con_pool(host,
                 key_file=None,
                 cert_file=None,
                 socket_timeout=15.0,
                 max_pool_size=3,
                 verify_https=True):
    
    kwargs = {
        "timeout": socket_timeout,
        "maxsize": max_pool_size,
        "block": True,
        }

    if key_file is not None and cert_file is not None:
        kwargs["key_file"] = key_file
        kwargs["cert_file"] = cert_file

    if urlparse(host).scheme == "https":
        kwargs["ssl_version"] = ssl.PROTOCOL_TLSv1
        if verify_https:
            kwargs["cert_reqs"] = "CERT_REQUIRED"
            kwargs["ca_certs"] = getattr(settings, "RESTCLIENTS_CA_BUNDLE",
                                         "/etc/ssl/certs/ca-bundle.crt")

    return connection_from_url(host, **kwargs)
256571
def _get_conn(self, host, port):
        """"""
        host_key = (host, port)
        if host_key not in self.conns:
            self.conns[host_key] = KafkaConnection(
                host,
                port,
                timeout=self.timeout
            )

        return self.conns[host_key]
1009718
public function configure(Memcache $memcache, array $connections)
    {
        foreach ($connections as $conn) {
            $memcache->addServer($conn['host'], $conn['port'], $conn['persistent'], $conn['weight'], $conn['timeout'], $conn['retry_interval']);
        }

        return $memcache;
    }
420154
def _get_redis_cache_opts():
    '''
    
    '''
    return {
        'host': __opts__.get('cache.redis.host', 'localhost'),
        'port': __opts__.get('cache.redis.port', 6379),
        'unix_socket_path': __opts__.get('cache.redis.unix_socket_path', None),
        'db': __opts__.get('cache.redis.db', '0'),
        'password': __opts__.get('cache.redis.password', ''),
        'cluster_mode': __opts__.get('cache.redis.cluster_mode', False),
        'startup_nodes': __opts__.get('cache.redis.cluster.startup_nodes', {}),
        'skip_full_coverage_check': __opts__.get('cache.redis.cluster.skip_full_coverage_check', False),
    }
1263471
def cache(self, name='cache', default_timeout=3600):
        
        return Cache(self, name=name, default_timeout=default_timeout)
278525
def enable_memcache(source=None, release=None, package=None):
    
    _release = None
    if release:
        _release = release
    else:
        _release = os_release(package, base='icehouse')
    if not _release:
        _release = get_os_codename_install_source(source)

    return CompareOpenStackReleases(_release) >= 'mitaka'
1006312
def get(self, key):
    
    

    try:
      try:
        obj = self.bucket.get(key)
      except couchbase.exception.MemcachedError, inst: 
        if str(inst) == "Memcached error #1:  Not found":
          # for some reason the py cb client raises an error when
          # a key isnt found, instead we just want a none value.
          obj = None
        else:
          raise
      except:
        raise
      
      if obj:
        return json.loads(obj[2])
      else:
        return None

    except:
      raise
256205
def get_cache_token(self, token):
        

        if self.conn is None:
            raise CacheException('Redis is not connected')

        token_data = self.conn.get(token)
        token_data = json.loads(token_data) if token_data else None

        return token_data
1212597
public static MemcachedManagerBuilder memcachierAddOn() {
        final String memcachierServers = System.getenv("MEMCACHIER_SERVERS");
        return memcachedConfig()
                .username(System.getenv("MEMCACHIER_USERNAME"))
                .password(System.getenv("MEMCACHIER_PASSWORD"))
                .url(memcachierServers == null ? DEFAULT_URL : memcachierServers);
    }
1365244
def read(key, parameters = {})
      begin
        @memcached.get(normalize(key, parameters))
      rescue Memcached::NotFound, Memcached::Stored
        nil
      end
    end
324337
def pool_memcached_connections(func):
    
    if isgeneratorfunction(func):
        def wrapper(*nargs, **kwargs):
            with memcached_client():
                for result in func(*nargs, **kwargs):
                    yield result
    else:
        def wrapper(*nargs, **kwargs):
            with memcached_client():
                return func(*nargs, **kwargs)

    return update_wrapper(wrapper, func)