momento-redis


Namemomento-redis JSON
Version 0.1.2 PyPI version JSON
download
home_page
SummaryMomento wrapper for redis/redis-py
upload_time2023-08-28 22:27:04
maintainer
docs_urlNone
authorMomento
requires_python>=3.7,<3.12
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="https://docs.momentohq.com/img/logo.svg" alt="logo" width="400"/>

[![project status](https://momentohq.github.io/standards-and-practices/badges/project-status-official.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md)
[![project stability](https://momentohq.github.io/standards-and-practices/badges/project-stability-alpha.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md) 


# Momento Python Redis compatibility client

## What and why?

This project provides a Momento-backed implementation of [redis/redis-py](https://github.com/redis/redis-py)
The goal is to provide a drop-in replacement for [redis/redis-py](https://github.com/redis/redis-py) so that you can
use the same code with either a Redis server or with the Momento Cache service!

## Usage

To switch your existing `redis/redis-py` application to use Momento, you only need to change the code where you construct
your client object:

### With redis-py client

```python
# Import the redis module
from redis import Redis
# Replace these values with your Redis server's details
_REDIS_HOST = 'my.redis-server.com';
_REDIS_PORT = 6379;
_REDIS_DB = 0
_REDIS_PASSWORD = 'mypasswd';
# Create a Redis client
redis_client = Redis(host=_REDIS_HOST, port=_REDIS_PORT, db=_REDIS_DB, password=_REDIS_PASSWORD)
```

### With Momento's Redis compatibility client

```python
import datetime
# Import the Momento redis compatibility client.
import momento
from momento_redis import MomentoRedis

_CACHE_NAME = "my-cache"
# Initialize Momento client.
redis_client = MomentoRedis(
    momento.CacheClient(
        momento.Configurations.Laptop.latest(),
        momento.CredentialProvider.from_environment_variable("MOMENTO_AUTH_TOKEN"),
        datetime.timedelta(seconds=60)
    ),
    _CACHE_NAME
)
```

**NOTE**: The Momento `redis/redis-py` implementation currently supports simple key/value pairs (`GET`, `SET`, `DELETE`) 
as well as `INCR/INCRBY` and `DECR/DECRBY`. We will continue to add support for additional Redis APIs in the future; 
for more information see the [current Redis API support](#current-redis-api-support) section later in this doc.

## Installation

The Momento Python Redis compatibility client is [available on PyPi](https://pypi.org/project/momento-redis/).
You can install it via:

```bash
poetry add momento-redis
```

## Examples

### Prerequisites

To run these examples, you will need a Momento auth token. You can generate one using the [Momento Console](https://console.gomomento.com).

The examples will utilize the auth token via an environment variable `MOMENTO_AUTH_TOKEN` that you set.

### Basic example

In the [`examples/`](./examples/) directory, you will find a simple CLI app, `basic.py`, that does some basic sets and 
gets on strings. It uses the Momento Redis client by default, but you can also pass a '-r' flag on the command line 
to use a Redis client instead to verify that the two clients are functioning identically. You may also pass a 
'-h <hostname>' flag and/or a '-p <port>' flag to specify a specific host and port for the Redis client. By 
default, `localhost` and `6379` are used.

Here's an example run against Momento Cache:

```bash
cd examples/
export MOMENTO_AUTH_TOKEN=<your momento auth token goes here>
python basic.py
```

And the output should look like this:

```bash
Issuing a 'get' for 'key1', which we have not yet set.
result: None
Issuing a 'set' for 'key1', with value 'value1'.
result: True
Issuing another 'get' for 'key1'.
result: b'bar'
done
```

Running the script using Redis (`python basic.py -r`) should produce identical output.

## Current Redis API Support

This library supports the most popular Redis APIs, but does not yet support all Redis APIs. We currently support the most
common APIs related to string values (GET, SET, DELETE, INCR, DECR). We will be adding support for additional
APIs in the future. If there is a particular API that you need support for, please drop by our [Discord](https://discord.com/invite/3HkAKjUZGq)
or e-mail us at [support@momentohq.com](mailto:support@momentohq.com) and let us know!

### Type Checking

To allow the use of tools such as `mypy` and in-IDE type checking to tell you if you're using any APIs that we 
don't support yet, we provide our own `MomentoRedisBase` abstract base class which explicitly lists out 
the APIs we currently support. Simply use the class as a type annotation for your client:

```python
from momento_redis import MomentoRedis, MomentoRedisBase
redis_client: MomentoRedisBase = MomentoRedis(...)
```

Once the client is typed using the abstract base class, static analysis tools will allow you to find 
calls to as yet unsupported APIs.

----------------------------------------------------------------------------------------
For more info, visit our website at [https://gomomento.com](https://gomomento.com)!

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "momento-redis",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<3.12",
    "maintainer_email": "",
    "keywords": "",
    "author": "Momento",
    "author_email": "hello@momentohq.com",
    "download_url": "https://files.pythonhosted.org/packages/d6/0b/e4e049f783bba7926b5fe896cdb3bb78bf8d504deaa5b7ccf5121ee8841e/momento_redis-0.1.2.tar.gz",
    "platform": null,
    "description": "<img src=\"https://docs.momentohq.com/img/logo.svg\" alt=\"logo\" width=\"400\"/>\n\n[![project status](https://momentohq.github.io/standards-and-practices/badges/project-status-official.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md)\n[![project stability](https://momentohq.github.io/standards-and-practices/badges/project-stability-alpha.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md) \n\n\n# Momento Python Redis compatibility client\n\n## What and why?\n\nThis project provides a Momento-backed implementation of [redis/redis-py](https://github.com/redis/redis-py)\nThe goal is to provide a drop-in replacement for [redis/redis-py](https://github.com/redis/redis-py) so that you can\nuse the same code with either a Redis server or with the Momento Cache service!\n\n## Usage\n\nTo switch your existing `redis/redis-py` application to use Momento, you only need to change the code where you construct\nyour client object:\n\n### With redis-py client\n\n```python\n# Import the redis module\nfrom redis import Redis\n# Replace these values with your Redis server's details\n_REDIS_HOST = 'my.redis-server.com';\n_REDIS_PORT = 6379;\n_REDIS_DB = 0\n_REDIS_PASSWORD = 'mypasswd';\n# Create a Redis client\nredis_client = Redis(host=_REDIS_HOST, port=_REDIS_PORT, db=_REDIS_DB, password=_REDIS_PASSWORD)\n```\n\n### With Momento's Redis compatibility client\n\n```python\nimport datetime\n# Import the Momento redis compatibility client.\nimport momento\nfrom momento_redis import MomentoRedis\n\n_CACHE_NAME = \"my-cache\"\n# Initialize Momento client.\nredis_client = MomentoRedis(\n    momento.CacheClient(\n        momento.Configurations.Laptop.latest(),\n        momento.CredentialProvider.from_environment_variable(\"MOMENTO_AUTH_TOKEN\"),\n        datetime.timedelta(seconds=60)\n    ),\n    _CACHE_NAME\n)\n```\n\n**NOTE**: The Momento `redis/redis-py` implementation currently supports simple key/value pairs (`GET`, `SET`, `DELETE`) \nas well as `INCR/INCRBY` and `DECR/DECRBY`. We will continue to add support for additional Redis APIs in the future; \nfor more information see the [current Redis API support](#current-redis-api-support) section later in this doc.\n\n## Installation\n\nThe Momento Python Redis compatibility client is [available on PyPi](https://pypi.org/project/momento-redis/).\nYou can install it via:\n\n```bash\npoetry add momento-redis\n```\n\n## Examples\n\n### Prerequisites\n\nTo run these examples, you will need a Momento auth token. You can generate one using the [Momento Console](https://console.gomomento.com).\n\nThe examples will utilize the auth token via an environment variable `MOMENTO_AUTH_TOKEN` that you set.\n\n### Basic example\n\nIn the [`examples/`](./examples/) directory, you will find a simple CLI app, `basic.py`, that does some basic sets and \ngets on strings. It uses the Momento Redis client by default, but you can also pass a '-r' flag on the command line \nto use a Redis client instead to verify that the two clients are functioning identically. You may also pass a \n'-h <hostname>' flag and/or a '-p <port>' flag to specify a specific host and port for the Redis client. By \ndefault, `localhost` and `6379` are used.\n\nHere's an example run against Momento Cache:\n\n```bash\ncd examples/\nexport MOMENTO_AUTH_TOKEN=<your momento auth token goes here>\npython basic.py\n```\n\nAnd the output should look like this:\n\n```bash\nIssuing a 'get' for 'key1', which we have not yet set.\nresult: None\nIssuing a 'set' for 'key1', with value 'value1'.\nresult: True\nIssuing another 'get' for 'key1'.\nresult: b'bar'\ndone\n```\n\nRunning the script using Redis (`python basic.py -r`) should produce identical output.\n\n## Current Redis API Support\n\nThis library supports the most popular Redis APIs, but does not yet support all Redis APIs. We currently support the most\ncommon APIs related to string values (GET, SET, DELETE, INCR, DECR). We will be adding support for additional\nAPIs in the future. If there is a particular API that you need support for, please drop by our [Discord](https://discord.com/invite/3HkAKjUZGq)\nor e-mail us at [support@momentohq.com](mailto:support@momentohq.com) and let us know!\n\n### Type Checking\n\nTo allow the use of tools such as `mypy` and in-IDE type checking to tell you if you're using any APIs that we \ndon't support yet, we provide our own `MomentoRedisBase` abstract base class which explicitly lists out \nthe APIs we currently support. Simply use the class as a type annotation for your client:\n\n```python\nfrom momento_redis import MomentoRedis, MomentoRedisBase\nredis_client: MomentoRedisBase = MomentoRedis(...)\n```\n\nOnce the client is typed using the abstract base class, static analysis tools will allow you to find \ncalls to as yet unsupported APIs.\n\n----------------------------------------------------------------------------------------\nFor more info, visit our website at [https://gomomento.com](https://gomomento.com)!\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Momento wrapper for redis/redis-py",
    "version": "0.1.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e70f7084b6a81f6b3e294226a5618bd5e1ddafa5811be19f7f2e16e38b81c3e8",
                "md5": "4a2fccd86954627e07c6fdd8bacd5c4b",
                "sha256": "384256319fb0db10f8ba48d91d728107d1745535c81f81ce9ee86fe723ab2fd7"
            },
            "downloads": -1,
            "filename": "momento_redis-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4a2fccd86954627e07c6fdd8bacd5c4b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<3.12",
            "size": 12481,
            "upload_time": "2023-08-28T22:27:02",
            "upload_time_iso_8601": "2023-08-28T22:27:02.977204Z",
            "url": "https://files.pythonhosted.org/packages/e7/0f/7084b6a81f6b3e294226a5618bd5e1ddafa5811be19f7f2e16e38b81c3e8/momento_redis-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d60be4e049f783bba7926b5fe896cdb3bb78bf8d504deaa5b7ccf5121ee8841e",
                "md5": "0a9716ee530af07a650675319d6f5877",
                "sha256": "f61892e389bb40b4093b4839d81872df120aa17cc34c92d76b1dc73a92609d5b"
            },
            "downloads": -1,
            "filename": "momento_redis-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "0a9716ee530af07a650675319d6f5877",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<3.12",
            "size": 14829,
            "upload_time": "2023-08-28T22:27:04",
            "upload_time_iso_8601": "2023-08-28T22:27:04.592245Z",
            "url": "https://files.pythonhosted.org/packages/d6/0b/e4e049f783bba7926b5fe896cdb3bb78bf8d504deaa5b7ccf5121ee8841e/momento_redis-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-28 22:27:04",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "momento-redis"
}
        
Elapsed time: 0.10943s