本文へスキップ
hdknr blog
戻る

redis

更新日:

Elasic Cache for Redis

バージョン

$ redis-cli --version
redis-cli 5.0.7

$ redis-server -v
Redis server v=5.0.7 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=66bd629f924ac924

接続:

REDIS_URL=redis://mycloud-stage-redis-nc.sigrvp.ng.0001.apne1.cache.amazonaws.com:6379/0
$ export $(cat .env|xargs)
$ redis-cli -u $REDIS_URL PING
PONG

Python

クラスターモードへの接続

import logging
from redis.cluster import RedisCluster

ENDPOINT = "mycloud-stage-redis-test.sigrvp.clustercfg.apne1.cache.amazonaws.com"
logging.basicConfig(level=logging.INFO)
redis = RedisCluster(host=ENDPOINT, port="6379")

if redis.ping():
    logging.info("Connected to Redis")

django-redis:

app/reids.py:

from django_redis.client import DefaultClient
from redis.cluster import RedisCluster

class RedisClusterClient(DefaultClient):
    def connect(self, index):
        url = self._server[index]
        return RedisCluster.from_url(url)

app/settings.py:

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://youcloud-stage-redis-test.sigrvp.clustercfg.apne1.cache.amazonaws.com:6379/0",
        "OPTIONS": {
            "CLIENT_CLASS": "app.redis.RedisClusterClient",
        },
    }
}

セキュリティグループ設定

AOF(Append-Only File)

Data Tiering

クラスターモード



前の記事
Celery AWS ECS
次の記事
Managed k8s