View the Contents of Redis Directly from the Terminal in Django

Django
2022-12-27 19:15 (2 years ago) ytyng

Here is the method to directly view the contents of Django Redis from the Django shell.

./manage.py shell
from django_redis import get_redis_connection

# Create a Redis connection
r = get_redis_connection('default')

# Get a list of keys with a limit
r.scan(count=1000)

# Get a list of keys with a pattern
r.keys('ranking_cache_*')

# The contents are pickled, so they cannot be read as is
r.get('my_cache_key')

# Unpickle to read the contents
import pickle
pickle.loads(r.get('my_cache_key'))
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Comments

Archive

2025
2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011