Ejemplo n.º 1
0
def rfunc(info):
    #
    info.setdefault('host', '127.0.0.1')
    info.setdefault('port', 6379)

    #
    conn_kwargs = dict(
        host=info['host'],
        port=int(info['port']),
    )

    #
    print('# Connect')
    print(pformat(conn_kwargs, indent=4, width=1))

    #
    conn = None

    try:
        #
        conn = Connection(**conn_kwargs)

        #
        res = conn.execute('info')

        #
        print('# Result')
        print(res)

    finally:
        #
        conn = None
class RedisCoreClient_old(j.application.JSBaseClass):

    __jslocation__ = "j.clients.credis_core"

    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 execute(self, *args):
        if self._credis:
            return self._client.execute(*args)
        else:
            return self._client.execute_command(*args)

    def get(self, *args):
        return self.execute("GET", *args)

    def set(self, *args):
        return self.execute("SET", *args)

    def hset(self, *args):
        return self.execute("HSET", *args)

    def hget(self, *args):
        return self.execute("HGET", *args)

    def hdel(self, *args):
        return self.execute("HDEL", *args)

    def keys(self, *args):
        return self.execute("KEYS", *args)

    def hkeys(self, *args):
        return self.execute("HKEYS", *args)

    def delete(self, *args):
        return self.execute("DEL", *args)

    def incr(self, *args):
        return self.execute("INCR", *args)
Ejemplo n.º 3
0
        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
Ejemplo n.º 4
0
        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
Ejemplo n.º 5
0
    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")
Ejemplo n.º 6
0
    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")
Ejemplo n.º 7
0
#!/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')
Ejemplo n.º 8
0
#!/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),
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
class RedisCoreClient(j.baseclasses.object):

    __jslocation__ = "j.clients.credis_core"

    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")

    def execute(self, *args):
        if self._credis:
            return self._client.execute(*args)
        else:
            return self._client.execute_command(*args)

    def get(self, *args):
        return self.execute("GET", *args)

    def set(self, *args):
        return self.execute("SET", *args)

    def hset(self, *args):
        return self.execute("HSET", *args)

    def hget(self, *args):
        return self.execute("HGET", *args)

    def hdel(self, *args):
        return self.execute("HDEL", *args)

    def keys(self, *args):
        return self.execute("KEYS", *args)

    def hkeys(self, *args):
        return self.execute("HKEYS", *args)

    def delete(self, *args):
        return self.execute("DEL", *args)

    def incr(self, *args):
        return self.execute("INCR", *args)

    def lpush(self, *args):
        return self.execute("LPUSH", *args)

    @property
    def client(self):
        if not self._client:
            import redis

            self._client = redis.Redis(
                unix_socket_path=j.core.db.connection_pool.
                connection_kwargs["path"],
                db=1)
        return self._client
Ejemplo n.º 11
0
    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")