def redis_reset(): j.clients.redis.core_stop() r_classic = j.clients.redis.core_get() from credis import Connection r = Connection(path="/sandbox/var/redis.sock") r.connect() assert r.execute(b"PING") == b"PONG" return r, r_classic
def test_simple(self): conn = Connection() assert conn.execute("SET", 1, 1) == b"OK" assert conn.execute("GET", 1) == b"1" # pipeline assert conn.execute_pipeline( ("SET", 1, 2), ("GET", 1), ) == (b"OK", b"2") assert conn.execute_pipeline( ("SET", 1, 1), ("INCR", 1), ("INCRBY", 1, 1), ("GET", 1), ) == (b"OK", 2, 3, b"3") # Connection with explicit db selection. conn_with_explicit_db = Connection(db=7) assert conn_with_explicit_db.execute("SET", 1, 1) == b"OK" assert conn_with_explicit_db.execute("GET", 1) == b"1" # pipeline assert conn_with_explicit_db.execute_pipeline( ("SET", 1, 2), ("GET", 1), ) == ( b"OK", b"2", ) assert conn_with_explicit_db.execute_pipeline( ("SET", 1, 1), ("INCR", 1), ("INCRBY", 1, 1), ("GET", 1), ) == (b"OK", 2, 3, b"3")
def redis_reset(): j.clients.redis.core_stop() r_classic = j.clients.redis.core_get() from credis import Connection r = Connection( path=j.core.tools.text_replace("{DIR_BASE}/var/redis.sock")) r.connect() assert r.execute(b"PING") == b"PONG" return r, r_classic
def _init(self): self._client_fallback = j.clients.redis.core_get() try: self._credis = True from credis import Connection self._client = Connection(path="/sandbox/var/redis.sock") self._client.connect() except Exception as e: self._credis = False self._client = j.clients.redis.core_get() if self._credis: assert self.execute("PING") == b'PONG' else: assert self.execute("PING")
def _init(self, **kwargs): try: self._credis = True from credis import Connection self._client = Connection(path="/sandbox/var/redis.sock") self._client.connect() except Exception as e: self._credis = False self._client = j.clients.redis.core_get() from redis import ConnectionError self._ConnectionError = ConnectionError if self._credis: assert self.execute("PING") == b"PONG" else: assert self.execute("PING")
#!/usr/bin/env python from credis import Connection conn = Connection() assert conn.execute('SET', 1, 1) == 'OK' assert conn.execute('GET', 1) == '1' # pipeline assert conn.execute_pipeline( ('SET', 1, 2), ('GET', 1), ) == ('OK', '2') assert conn.execute_pipeline( ('SET', 1, 1), ('INCR', 1), ('INCRBY', 1, 1), ('GET', 1), ) == ('OK', 2, 3, '3')
#!/usr/bin/env python from credis import Connection conn = Connection() assert conn.execute('SET', 1, 1) == b'OK' assert conn.execute('GET', 1) == b'1' # pipeline assert conn.execute_pipeline( ('SET', 1, 2), ('GET', 1), ) == (b'OK', b'2') assert conn.execute_pipeline( ('SET', 1, 1), ('INCR', 1), ('INCRBY', 1, 1), ('GET', 1), ) == (b'OK', 2, 3, b'3') # Connection with explicit db selection. conn_with_explicit_db = Connection(db=7) assert conn_with_explicit_db.execute('SET', 1, 1) == b'OK' assert conn_with_explicit_db.execute('GET', 1) == b'1' # pipeline assert conn_with_explicit_db.execute_pipeline( ('SET', 1, 2), ('GET', 1),
import aredis import asyncio_redis import time import cpipe import cpipelib import asyncio from aredis import StrictRedis from credis import Connection from credis.geventpool import ResourcePool import pandas as pd HOST = '127.0.0.1' PORT = 6379 NUM_INSERTS = 50000 credis_connection = Connection() hset_dict = dict() hget_dict = dict() def asyncio_redis_bench(): try: connection = yield from asyncio_redis.Pool.create(host=HOST, port=PORT, poolsize=10) connection.flushdb() start = time.time() for x in range(NUM_INSERTS): yield from connection.hset("words", "word|{}".format(x), "1") print('Asyncio HSET Done. Duration=', time.time() - start)