Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 23, 2025

This PR implements a comprehensive KV Store adapter package that provides a pluggable interface for Key-Value store operations with multiple backend implementations.

Overview

The package provides a common protocol for KV store operations supporting:

  • Basic operations: get, set, delete, exists
  • TTL (Time To Live): Automatic key expiration
  • Namespaces/Collections: Data organization into separate collections
  • Pattern matching: Wildcard key searches
  • Multiple backends: In-memory, disk-based, and Redis implementations

Package Structure

Each implementation is organized as its own sub-package:

# Memory implementation (thread-safe, fast)
from kv_store_adapter.memory import MemoryKVStore
store = MemoryKVStore()

# Disk implementation (persistent, file-based)
from kv_store_adapter.disk import DiskKVStore  
store = DiskKVStore("/path/to/data")

# Redis implementation (scalable, distributed)
from kv_store_adapter.redis import RedisKVStore
store = RedisKVStore(host="localhost", port=6379)

Key Features

Protocol Interface: All implementations follow the KVStoreProtocol abstract base class ensuring consistent behavior across backends.

Namespace Support: Data can be organized into collections for better isolation:

store.set("config", "production", namespace="app")
store.set("config", "debug", namespace="test") 

TTL Support: Keys can automatically expire using seconds, floats, or timedelta:

from datetime import timedelta
store.set("session", {"user_id": 1}, ttl=timedelta(hours=1))

Pattern Matching: Find keys using wildcard patterns:

store.keys(pattern="user:*")  # Find all user keys

Implementation Details

  • Memory Store: Thread-safe using threading.RLock, perfect for caching
  • Disk Store: Uses pickle for data serialization and JSON for metadata, survives restarts
  • Redis Store: Leverages Redis's native TTL and scalability features

Testing

The package includes comprehensive tests covering:

  • All protocol operations across implementations
  • TTL expiration behavior
  • Namespace isolation
  • Thread safety
  • Data persistence
  • Error handling
  • Edge cases

All 49 tests pass successfully, ensuring robust functionality across all implementations.

Usage Example

from kv_store_adapter.memory import MemoryKVStore
from datetime import timedelta

store = MemoryKVStore()

# Basic operations
store.set("user:1", {"name": "Alice", "age": 30})
user = store.get("user:1")

# With TTL and namespace
store.set("session:abc", {"user_id": 1}, 
          namespace="auth", 
          ttl=timedelta(hours=1))

# Pattern matching
users = store.keys(pattern="user:*")
namespaces = store.list_namespaces()

This implementation provides a clean, extensible foundation for KV store operations that can easily swap between different backends based on application needs.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Create a very simple namespaced UV package for a KV Store protocol with in memory, disk implementations, and redis implementations each implementation should be its own package along with the main package. The protocol should support get, set, delete,... Implement complete KV Store adapter with memory, disk, and Redis implementations Sep 23, 2025
Copilot AI requested a review from strawgate September 23, 2025 12:58
Copilot finished work on behalf of strawgate September 23, 2025 12:58
@strawgate
Copy link
Owner

bad bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants