django2.0.6接続redisクラスタの使用

1395 ワード

環境要件:
  django >= 1.8.x
python 2.7またはpython>=3.4
django-cluster-redisパッケージをインストールします.
pip install django-redis#注意django-redisバージョンは>=4.7.0 
  pip install django-cluster-redis
djangoプロジェクトのsettingsファイルで:
CACHES = {
  'default': {
    'BACKEND': 'django_redis.cache.RedisCache',
    'LOCATION': [
    'redis    ',
  ],  #     redis://IP:PORT/db_index,        ,   0 
    'OPTIONS': {
      'REDIS_CLIENT_CLASS': 'rediscluster.RedisCluster',
      'CONNECTION_POOL_CLASS': 'rediscluster.connection.ClusterConnectionPool',
      'CONNECTION_POOL_KWARGS': {
        'skip_full_coverage_check': True # AWS ElasticCache has disabled CONFIG commands
      }
    }
  }
}

SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
SESSION_CACHE_ALIAS = 'default'

viewでの使用方法:
1 2 3 4 5 6 from   django_redis  import   get_redis_connection     conn  =   get_redis_connection() conn.hgetall( 'key' ) ....
connオブジェクトには、基本的にすべてのredisコマンドがあります.
使用方法はconn.redisコマンド(パラメータ...)
ソース:https://www.cnblogs.com/liang3044/p/10587326.html