Skip to content

proxystore.connectors.redis

Redis connector implementation.

RedisKey

Bases: NamedTuple

Key to objects store in a Redis server.

Attributes:

  • redis_key (str) –

    Unique object ID.

RedisConnector

RedisConnector(hostname: str, port: int) -> None

Redis server connector.

Parameters:

  • hostname (str) –

    Redis server hostname.

  • port (int) –

    Redis server port.

Source code in proxystore/connectors/redis.py
def __init__(self, hostname: str, port: int) -> None:
    self.hostname = hostname
    self.port = port
    self._redis_client = redis.StrictRedis(host=hostname, port=port)

close()

close() -> None

Close the connector and clean up.

Source code in proxystore/connectors/redis.py
def close(self) -> None:
    """Close the connector and clean up."""
    pass

config()

config() -> dict[str, Any]

Get the connector configuration.

The configuration contains all the information needed to reconstruct the connector object.

Source code in proxystore/connectors/redis.py
def config(self) -> dict[str, Any]:
    """Get the connector configuration.

    The configuration contains all the information needed to reconstruct
    the connector object.
    """
    return {'hostname': self.hostname, 'port': self.port}

from_config() classmethod

from_config(config: dict[str, Any]) -> RedisConnector

Create a new connector instance from a configuration.

Parameters:

  • config (dict[str, Any]) –

    Configuration returned by .config().

Source code in proxystore/connectors/redis.py
@classmethod
def from_config(cls, config: dict[str, Any]) -> RedisConnector:
    """Create a new connector instance from a configuration.

    Args:
        config: Configuration returned by `#!python .config()`.
    """
    return cls(**config)

evict()

evict(key: RedisKey) -> None

Evict the object associated with the key.

Parameters:

  • key (RedisKey) –

    Key associated with object to evict.

Source code in proxystore/connectors/redis.py
def evict(self, key: RedisKey) -> None:
    """Evict the object associated with the key.

    Args:
        key: Key associated with object to evict.
    """
    self._redis_client.delete(key.redis_key)

exists()

exists(key: RedisKey) -> bool

Check if an object associated with the key exists.

Parameters:

  • key (RedisKey) –

    Key potentially associated with stored object.

Returns:

  • bool

    If an object associated with the key exists.

Source code in proxystore/connectors/redis.py
def exists(self, key: RedisKey) -> bool:
    """Check if an object associated with the key exists.

    Args:
        key: Key potentially associated with stored object.

    Returns:
        If an object associated with the key exists.
    """
    return bool(self._redis_client.exists(key.redis_key))

get()

get(key: RedisKey) -> bytes | None

Get the serialized object associated with the key.

Parameters:

  • key (RedisKey) –

    Key associated with the object to retrieve.

Returns:

  • bytes | None

    Serialized object or None if the object does not exist.

Source code in proxystore/connectors/redis.py
def get(self, key: RedisKey) -> bytes | None:
    """Get the serialized object associated with the key.

    Args:
        key: Key associated with the object to retrieve.

    Returns:
        Serialized object or `None` if the object does not exist.
    """
    return self._redis_client.get(key.redis_key)

get_batch()

get_batch(keys: Sequence[RedisKey]) -> list[bytes | None]

Get a batch of serialized objects associated with the keys.

Parameters:

  • keys (Sequence[RedisKey]) –

    Sequence of keys associated with objects to retrieve.

Returns:

  • list[bytes | None]

    List with same order as keys with the serialized objects or None if the corresponding key does not have an associated object.

Source code in proxystore/connectors/redis.py
def get_batch(self, keys: Sequence[RedisKey]) -> list[bytes | None]:
    """Get a batch of serialized objects associated with the keys.

    Args:
        keys: Sequence of keys associated with objects to retrieve.

    Returns:
        List with same order as `keys` with the serialized objects or \
        `None` if the corresponding key does not have an associated object.
    """
    return self._redis_client.mget([key.redis_key for key in keys])

put()

put(obj: bytes) -> RedisKey

Put a serialized object in the store.

Parameters:

  • obj (bytes) –

    Serialized object to put in the store.

Returns:

  • RedisKey

    Key which can be used to retrieve the object.

Source code in proxystore/connectors/redis.py
def put(self, obj: bytes) -> RedisKey:
    """Put a serialized object in the store.

    Args:
        obj: Serialized object to put in the store.

    Returns:
        Key which can be used to retrieve the object.
    """
    key = RedisKey(redis_key=str(uuid.uuid4()))
    self._redis_client.set(key.redis_key, obj)
    return key

put_batch()

put_batch(objs: Sequence[bytes]) -> list[RedisKey]

Put a batch of serialized objects in the store.

Parameters:

  • objs (Sequence[bytes]) –

    Sequence of serialized objects to put in the store.

Returns:

  • list[RedisKey]

    List of keys with the same order as objs which can be used to retrieve the objects.

Source code in proxystore/connectors/redis.py
def put_batch(self, objs: Sequence[bytes]) -> list[RedisKey]:
    """Put a batch of serialized objects in the store.

    Args:
        objs: Sequence of serialized objects to put in the store.

    Returns:
        List of keys with the same order as `objs` which can be used to \
        retrieve the objects.
    """
    keys = [RedisKey(redis_key=str(uuid.uuid4())) for _ in objs]
    self._redis_client.mset(
        {key.redis_key: obj for key, obj in zip(keys, objs)},
    )
    return keys