Store Configuration#

1) RedisStore#

RedisStore is developed based on the Redis API provided by redis-py.

In terms of Redis connection configuration management, the configuration naming of django-redis is basically used to reduce the learning cost.

from throttled import store

store.RedisStore(server="redis://127.0.0.1:6379/0", options={})
from throttled.asyncio import store

store.RedisStore(server="redis://127.0.0.1:6379/0", options={})

Arguments#

Parameter

Description

Default

server

Standard Redis URL, you can use it to connect to Redis in any deployment mode, see Store Backends.

"redis://localhost:6379/0"

options

<Options>

{}

Options#

Parameter

Description

Default

SOCKET_TIMEOUT

ConnectionPool parameters.

null

SOCKET_CONNECT_TIMEOUT

ConnectionPool parameters.

null

CONNECTION_POOL_KWARGS

ConnectionPool construction parameters.

{}

REDIS_CLIENT_KWARGS

RedisClient construction parameters.

{}

SENTINEL_KWARGS

Sentinel construction parameters.

{}

CONNECTION_FACTORY_CLASS

ConnectionFactory is used to create and maintain ConnectionPool.

Automatically select via the server scheme by default.

Standalone: "throttled.store.ConnectionFactory" Sentinel: "throttled.store.SentinelConnectionFactory" Cluster: "throttled.store.ClusterConnectionFactory"

REDIS_CLIENT_CLASS

RedisClient import path.

Automatically select sync/async mode by default.

Sync(Standalone/Sentinel): "redis.client.Redis"

Async(Standalone/Sentinel): "redis.asyncio.client.Redis"

Sync(Cluster): "redis.cluster.RedisCluster"

Async(Cluster): "redis.asyncio.cluster.RedisCluster"

CONNECTION_POOL_CLASS

ConnectionPool import path.

Automatically select via the server scheme and sync/async mode by default.

Sync(Standalone): "redis.connection.ConnectionPool"

Async(Standalone): "redis.asyncio.connection.ConnectionPool"

Sync(Sentinel): "redis.sentinel.SentinelConnectionPool"

Async(Sentinel): "redis.asyncio.sentinel.SentinelConnectionPool"

Cluster: “Disabled”

SENTINEL_CLASS

Sentinel import path.

Automatically select sync/async mode by default.

Sync: "redis.Sentinel"

Async: "redis.asyncio.Sentinel"

2) MemoryStore#

MemoryStore is essentially a memory-based LRU Cache with expiration time.

from throttled import store

store.MemoryStore(options={"MAX_SIZE": 10240})
from throttled.asyncio import store

store.MemoryStore(options={"MAX_SIZE": 10240})

Arguments#

options

<Options>

{}

Options#

Parameter

Description

Default

MAX_SIZE

Maximum capacity. When the number of stored key-value pairs exceeds MAX_SIZE, they will be eliminated according to the LRU policy.

1024