How to use pymemcache - 10 common examples

To help you get started, we’ve selected a few pymemcache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jxtech / wechatpy / tests / test_session.py View on Github external
def test_memcached_storage_init(self):
        if platform.system() == 'Windows':
            return

        from pymemcache.client import Client
        from wechatpy.session.memcachedstorage import MemcachedStorage

        servers = ("127.0.0.1", 11211)
        memcached = Client(servers)
        session = MemcachedStorage(memcached)
        client = WeChatClient(self.app_id, self.secret, session=session)
        self.assertTrue(isinstance(client.session, MemcachedStorage))
github DataDog / dd-trace-py / tests / contrib / pymemcache / test_client_mixin.py View on Github external
def make_client(self, mock_socket_values, **kwargs):
        tracer = get_dummy_tracer()
        Pin.override(pymemcache, tracer=tracer)
        self.client = pymemcache.client.base.Client((TEST_HOST, TEST_PORT), **kwargs)
        self.client.sock = MockSocket(list(mock_socket_values))
        return self.client
github DataDog / dd-trace-py / tests / contrib / pymemcache / test_client_mixin.py View on Github external
# 3p
import unittest
import pymemcache

# project
from ddtrace import Pin
from ddtrace.constants import ANALYTICS_SAMPLE_RATE_KEY
from ddtrace.contrib.pymemcache.patch import patch, unpatch
from ddtrace.ext import memcached as memcachedx, net
from .utils import MockSocket

from tests.test_tracer import get_dummy_tracer
from ...base import override_config


_Client = pymemcache.client.base.Client

TEST_HOST = 'localhost'
TEST_PORT = 117711


class PymemcacheClientTestCaseMixin(unittest.TestCase):
    """ Tests for a patched pymemcache.client.base.Client. """

    def get_spans(self):
        pin = Pin.get_from(self.client)
        tracer = pin.tracer
        spans = tracer.writer.pop()
        return spans

    def check_spans(self, num_expected, resources_expected, queries_expected):
        """A helper for validating basic span information."""
github DataDog / dd-trace-py / tests / contrib / pymemcache / test_client.py View on Github external
def make_client(self, mock_socket_values, **kwargs):
        tracer = get_dummy_tracer()
        Pin.override(pymemcache, tracer=tracer)
        self.client = pymemcache.client.base.Client((TEST_HOST, TEST_PORT), **kwargs)
        self.client.sock = MockSocket(list(mock_socket_values))
        return self.client
github DataDog / dd-trace-py / tests / contrib / pymemcache / test_client.py View on Github external
def test_get_unknown_error(self):
        client = self.make_client([b'foobarbaz\r\n'])

        def _get():
            client.get(b'key')

        pytest.raises(MemcacheUnknownError, _get)

        self.check_spans(1, ['get'], ['get key'])
github DataDog / dd-trace-py / tests / contrib / pymemcache / test_client.py View on Github external
def make_client_pool(self, hostname, mock_socket_values, serializer=None, **kwargs):
        mock_client = pymemcache.client.base.Client(
            hostname, serializer=serializer, **kwargs
        )
        tracer = get_dummy_tracer()
        Pin.override(mock_client, tracer=tracer)

        mock_client.sock = MockSocket(mock_socket_values)
        client = pymemcache.client.base.PooledClient(hostname, serializer=serializer)
        client.client_pool = pymemcache.pool.ObjectPool(lambda: mock_client)
        return mock_client
github youknowone / ring / tests / test_func_sync.py View on Github external
import sys
import ring
import pymemcache.client
import memcache
import redis
import diskcache

import pytest


pymemcache_client = pymemcache.client.Client(('127.0.0.1', 11211))
pythonmemcache_client = memcache.Client(["127.0.0.1:11211"])
redis_py_client = redis.StrictRedis()


try:
    import pylibmc
except ImportError:
    pylibmc_client = None
else:
    pylibmc_client = pylibmc.Client(['127.0.0.1'])


class StorageDict(dict):
    pass
github youknowone / ring / tests / test_func_sync.py View on Github external
import sys
import time
import shelve
import ring
import pymemcache.client
import memcache
import redis
import diskcache
from ring.func.lru_cache import LruCache

import pytest
from pytest_lazyfixture import lazy_fixture


pymemcache_client = pymemcache.client.Client(('127.0.0.1', 11211))
pythonmemcache_client = memcache.Client(["127.0.0.1:11211"])
redis_py_client = redis.StrictRedis()


try:
    import pylibmc
except ImportError:
    pylibmc_client = None
else:
    pylibmc_client = pylibmc.Client(['127.0.0.1'])


class StorageDict(dict):
    pass
github alisaifee / flask-limiter / tests / test_strategy.py View on Github external
def setUp(self):
        redis.Redis().flushall()
        pymemcache.client.Client(('localhost', 11211)).flush_all()
github jxtech / wechatpy / tests / test_session.py View on Github external
def test_memcached_storage_access_token(self):
        if platform.system() == 'Windows':
            return

        from pymemcache.client import Client
        from wechatpy.session.memcachedstorage import MemcachedStorage

        servers = ("127.0.0.1", 11211)
        memcached = Client(servers)
        session = MemcachedStorage(memcached)
        client = WeChatClient(self.app_id, self.secret, session=session)
        with HTTMock(wechat_api_mock):
            token = client.fetch_access_token()
            self.assertEqual('1234567890', token['access_token'])
            self.assertEqual(7200, token['expires_in'])
            self.assertEqual('1234567890', client.access_token)