Skip to content

v2.0.0

Choose a tag to compare

@SerGeRybakov SerGeRybakov released this 10 Dec 20:13
· 5 commits to main since this release
d783a56

[2.0.0] - 2025-12-10

⚠️ BREAKING CHANGES

This release contains breaking changes that require migration for Redis storage users.

  1. Redis storage now requires redis_client parameter - removed **kwargs support for Redis connection parameters
  2. Redis keys format changed - v1.x data is incompatible with v2.0.0 (migration required)
  3. CallGate.from_file() requires redis_client parameter when restoring Redis storage gates

Added

  • Redis Cluster Support: CallGate now supports Redis clusters in addition to single Redis instances
  • Pre-initialized Redis Client Support: New redis_client parameter accepts pre-initialized Redis or RedisCluster clients
  • Enhanced Type Safety: Better type annotations and IDE support for Redis configurations
  • New Error Type: CallGateRedisConfigurationError for Redis configuration issues
  • Code examples

Changed

  • Redis Storage Initialization: redis_client parameter is now required (removed **kwargs)
  • Redis Keys Format: Keys now use hash tags for cluster support ({gate_name} instead of gate_name)
  • Improved Documentation: All docstrings converted to English with RST format
  • Test Infrastructure: Added comprehensive cluster tests with fault tolerance scenarios
  • Makefile Enhancements: Added cluster test targets for all Python versions (3.9-3.14)

Fixed

  • Connection Validation: Added ping() validation for Redis clients during CallGate initialization
  • Serialization Handling: Improved serialization for RedisStorage with pre-initialized clients
  • Docker Compose Configuration: Fixed cluster configuration with proper network settings
  • Multiprocessing Support: Fixed pickling issues for all storage types

Removed

  • **kwargs in CallGate.init(): No longer accepts Redis connection parameters (host, port, db, etc.)
  • Legacy Redis Configuration: Removed automatic Redis client creation from kwargs
  • Old Redis Keys Format: Keys without hash tags are no longer created

⚠️ MIGRATION GUIDE v1.x → v2.x

BREAKING CHANGES SUMMARY:

  1. Redis storage requires redis_client parameter (removed **kwargs support)
  2. Redis keys format changed - old v1.x data is incompatible with v2.x
  3. CallGate.from_file() requires redis_client for Redis storage

Data Migration for Redis Storage

Redis keys format has changed - old v1.x data will NOT be accessible in v2.x

Step 1: Export data using v1.x and Python REPL

# Using CallGate v1.x
>>> from call_gate import CallGate
>>> redis_kwargs = {"host": "localhost", "port": 6379, "db": 15}
>>> gate = CallGate("my_gate", 60, 1, storage="redis", **redis_kwargs)
>>> gate.to_file("gate_backup.json")

Step 2: Upgrade call-gate version

pip install call-gate --upgrade

Step 3: Import data using v2.x and Python REPL

# Using CallGate v2.x
>>> from call_gate import CallGate
>>> from redis import Redis
>>> redis_kwargs = {"host": "localhost", "port": 6379, "db": 15}
>>> client = Redis(**redis_kwargs, decode_responses=True)
>>> gate = CallGate.from_file("gate_backup.json", storage="redis", redis_client=client) # Data is automatically written to Redis with new key format
>>> gate.state

It's not recommended to insert step 3 into your business logic as it will rewrite your actual data from the file contents on each restart.

Why keys changed:

  • v1.x keys: gate_name, gate_name:sum, gate_name:timestamp
  • v2.x keys: {gate_name}, {gate_name}:sum, {gate_name}:timestamp
  • Hash tags {...} ensure all keys for one gate are in the same Redis Cluster slot

API Changes

Before (v1.x):

redis_kwargs = {"host": "localhost", "port": 6379, "db": 15}

gate = CallGate(
    name="my_gate",
    gate_size=60,
    frame_step=1,
    storage="redis",
    **redis_kwargs
)

After (v2.x):

from redis import Redis

redis_kwargs = {"host": "localhost", "port": 6379, "db": 15}

client = Redis(**redis_kwargs, decode_responses=True)
gate = CallGate(
    name="my_gate", 
    gate_size=60,
    frame_step=1,
    storage="redis",
    redis_client=client  # Required parameter
)

Redis Cluster Usage

from redis import RedisCluster
from redis.cluster import ClusterNode

cluster_client = RedisCluster(
    startup_nodes=[
        ClusterNode("node1", 7001),
        ClusterNode("node2", 7002), 
        ClusterNode("node3", 7003)
    ],
    decode_responses=True,
    skip_full_coverage_check=True
)

gate = CallGate(
    name="cluster_gate",
    gate_size=60,
    frame_step=1,
    storage="redis",
    redis_client=cluster_client
)