Skip to main content
logo

project status project stability

Momento Python Redis compatibility client

What and why?

This project provides a Momento-backed implementation of redis/redis-py The goal is to provide a drop-in replacement for 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

# 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

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 section later in this doc.

Installation

The Momento Python Redis compatibility client is available on PyPi. You can install it via:

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.

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

Basic example

In the 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 ' flag and/or a '-p ' 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:

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

And the output should look like this:

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 or e-mail us at 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:

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!

Metadata

Release files for momento-redis 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for momento-redis 0.1.2
File Size Uploaded Provenance
momento_redis-0.1.2.tar.gz 14.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for momento-redis 0.1.2
File Interpreter ABI Platform
momento_redis-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.3 kB

Release files / momento_redis-0.1.2.tar.gz

Download URL momento_redis-0.1.2.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f61892e389bb40b4093b4839d81872df120aa17cc34c92d76b1dc73a92609d5b
BLAKE2b-256 checksum
How to use checksums
d60be4e049f783bba7926b5fe896cdb3bb78bf8d504deaa5b7ccf5121ee8841e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.12 Linux/5.15.0-1042-azure

Release files / momento_redis-0.1.2-py3-none-any.whl

Download URL momento_redis-0.1.2-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
384256319fb0db10f8ba48d91d728107d1745535c81f81ce9ee86fe723ab2fd7
BLAKE2b-256 checksum
How to use checksums
e70f7084b6a81f6b3e294226a5618bd5e1ddafa5811be19f7f2e16e38b81c3e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.12 Linux/5.15.0-1042-azure

Security for momento-redis 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page