Storage Backends¶
Storage scheme¶
limits uses a url style storage scheme notation (similar to the JDBC driver connection string notation) for configuring and initializing storage backends. This notation additionally provides a simple mechanism to both identify and configure the backend implementation based on a single string argument.
The storage scheme follows the format {scheme}://{parameters}
limits.storage.storage_from_string()
is provided to
lookup and construct an instance of a storage based on the storage scheme. For example:
import limits.storage
uri = "redis://localhost:9999"
options = {}
redis_storage = limits.storage.storage_from_string(uri, **options)
The additional options key-word arguments are passed as is to the constructor of the storage and handled differently by each implementation. Please refer to the class documentation of Backend Implementations for details.
Examples¶
In-Memory¶
The in-memory storage (limits.storage.MemoryStorage
) takes no parameters so the only relevant value is memory://
Memcached¶
Requires the location of the memcached server(s). As such the parameters is a comma separated list of
{host}:{port}
locations such asmemcached://localhost:11211
ormemcached://localhost:11211,localhost:11212,192.168.1.1:11211
etc… or a path to a unix domain socket such asmemcached:///var/tmp/path/to/sock
Depends on: pymemcache
Memcached on Google App Engine¶
Requires that you are working in the GAE SDK and have those API libraries available. :code: gaememcached://
Redis¶
Requires the location of the redis server and optionally the database number.
redis://localhost:6379
orredis://localhost:6379/n
(for database n).If the redis server is listening over a unix domain socket you can use
redis+unix:///path/to/sock
orredis+unix:///path/to/socket?db=n
(for database n).If the database is password protected the password can be provided in the url, for example
redis://:foobared@localhost:6379
orredis+unix//:foobered/path/to/socket
if using a UDS..Depends on: redis-py
Redis over SSL¶
The official Redis client
redis-py
supports redis connections over SSL with the scheme You can add ssl related parameters in the url itself, for example:rediss://localhost:6379/0?ssl_ca_certs=./tls/ca.crt&ssl_keyfile=./tls/client.key
.Depends on: redis-py
Redis with Sentinel¶
Requires the location(s) of the redis sentinal instances and the service-name that is monitored by the sentinels.
redis+sentinel://localhost:26379/my-redis-service
orredis+sentinel://localhost:26379,localhost:26380/my-redis-service
.If the database is password protected the password can be provided in the url, for example
redis+sentinel://:sekret@localhost:26379/my-redis-service
Depends on: redis-py
Redis Cluster¶
Requires the location(s) of the redis cluster startup nodes (One is enough).
redis+cluster://localhost:7000
orredis+cluster://localhost:7000,localhost:70001
Depends on: redis-py-cluster