File: redis.pyi

package info (click to toggle)
python-django-stubs 5.2.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,832 kB
  • sloc: python: 5,185; makefile: 15; sh: 8
file content (54 lines) | stat: -rw-r--r-- 2,267 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from collections.abc import Callable, Iterable, Mapping
from datetime import timedelta
from typing import Any, Protocol, SupportsInt, TypeAlias, overload, type_check_only

from _typeshed import ReadableBuffer
from django.core.cache.backends.base import BaseCache
from redis._parsers import BaseParser
from redis.client import Redis
from redis.connection import ConnectionPool

@type_check_only
class _RedisCacheClientSerializer(Protocol):
    def dumps(self, obj: Any) -> bytes: ...
    @overload
    def loads(self, data: SupportsInt) -> int: ...
    @overload
    def loads(self, data: ReadableBuffer) -> Any: ...

class RedisSerializer:
    def __init__(self, protocol: int | None = None) -> None: ...
    def dumps(self, obj: Any) -> bytes: ...
    @overload
    def loads(self, data: SupportsInt) -> int: ...
    @overload
    def loads(self, data: ReadableBuffer) -> Any: ...

# Taken from https://github.com/redis/redis-py/blob/6b8978/redis/typing.py
_Key: TypeAlias = str | bytes | memoryview
_Expiry: TypeAlias = int | timedelta

class RedisCacheClient:
    def __init__(
        self,
        servers: list[str],
        serializer: str | Callable[[], _RedisCacheClientSerializer] | _RedisCacheClientSerializer | None = None,
        pool_class: str | type[ConnectionPool] | None = None,
        parser_class: str | type[BaseParser] | None = None,
        **options: Any,
    ) -> None: ...
    def get_client(self, key: _Key | None = None, *, write: bool = False) -> Redis: ...
    def add(self, key: _Key, value: Any, timeout: _Expiry | None) -> bool: ...
    def get(self, key: _Key, default: Any) -> Any: ...
    def set(self, key: _Key, value: Any, timeout: _Expiry | None) -> None: ...
    def touch(self, key: _Key, timeout: _Expiry) -> bool: ...
    def delete(self, key: _Key) -> bool: ...
    def get_many(self, keys: Iterable[_Key]) -> dict[_Key, Any]: ...
    def has_key(self, key: _Key) -> bool: ...
    def incr(self, key: _Key, delta: int) -> Any: ...
    def set_many(self, data: Mapping[_Key, Any], timeout: _Expiry) -> None: ...
    def delete_many(self, keys: Iterable[_Key]) -> None: ...
    def clear(self) -> bool: ...

class RedisCache(BaseCache):
    def __init__(self, server: str | list[str], params: dict[str, Any]) -> None: ...