Skip to main content

Redis Client Wrapper

A convenient Redis client wrapper with JSON and datetime support.

Installation

Requires Redis server and redis-py library:

pip install redis

Usage

Initialization

from dgredis.conf import RedisConfig
from dgredis import RedisClient

config = RedisCoonfig(
    host="localhost",
    port=6379,
    password=None
)

client = RedisClient(config)

Core Methods

JSON Operations

# Store JSON data
data = {"name": "John", "date": datetime.now()}
client.set_json_key("user:1", data, ttl=3600)

# Retrieve JSON data
result = client.get_json_key("user:1")

Basic Key Operations

# Set value
client.set_key("last_update", datetime.now(), ttl=60)

# Get value
last_update = client.get_key("last_update")

Key Type Check

key_type = client.get_key_type("user:1")

Features

  1. Automatic serialization/deserialization:

    • datetime/date objects to/from ISO format
    • Complex structures (dict, list, tuple, set) to/from JSON
  2. Time-to-live (TTL) support for keys

  3. Support for both JSON documents (*_json_key methods) and simple keys

Technical Details

Serialization Behavior

  • Dates and datetimes are stored in ISO8601 format (UTC)
  • Nested structures are automatically handled recursively
  • Original Redis types are preserved when possible

Error Handling

  • Invalid dates fall back to string values
  • JSON decode errors return raw values

Requirements

  1. Redis server 4.0+ for JSON functionality
  2. Python 3.7+ (uses datetime.fromisoformat())

Limitations

  1. JSON operations require RedisJSON module
  2. Custom classes are not automatically serialized
  3. Timezone-naive datetimes are assumed to be in local timezone

Examples

Working with Nested Structures

data = {
    "user": "Alice",
    "login_dates": [datetime(2023,1,1), datetime(2023,1,15)],
    "preferences": {"dark_mode": True}
}
client.set_json_key("user:alice", data)

TTL Management

# Set key with 5 minute expiration
client.set_key("temp_data", {"value": 42}, ttl=300)

# Check remaining TTL (using native redis client)
remaining_ttl = client.client.ttl("temp_data")

Metadata

Release files for dgredis 1.0.1

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

Source distribution (sdist)

Source distribution for dgredis 1.0.1
File Size Uploaded Provenance Actions
dgredis-1.0.1.tar.gz 7.7 kB Without provenance Details for dgredis-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dgredis 1.0.1
File Interpreter ABI Platform Actions
dgredis-1.0.1-py3-none-any.whl Python 3 none any Details for dgredis-1.0.1-py3-none-any.whl

Total release size: 17.5 kB

Release files / dgredis-1.0.1.tar.gz

Download URL dgredis-1.0.1.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5aa3422a818130975bb3ff3394907c29581364146922a0ec0c6c3db4acac867b
BLAKE2b-256 checksum
How to use checksums
ca52e4bbbe6b538adea0c95cf494450c7c52ccb27a02d49e95ea34a831ba2a12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / dgredis-1.0.1-py3-none-any.whl

Download URL dgredis-1.0.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef9bb5fd38d31ce5b03eb662c29154fa5cdbb6268f36f329418629428a05ed84
BLAKE2b-256 checksum
How to use checksums
b995f39635281d4981a7ffe4e4ca1628eb8b2f21ed022e82f5fe1182ec5c0e36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for dgredis 1.0.1

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.

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