# How do I access redis values of keys stored from elsewhere

**URL:** <https://forum.djangoproject.com/t/how-do-i-access-redis-values-of-keys-stored-from-elsewhere/19929>\
**Category:** Forms & APIs\
**Created:** [March 31, 2023, 9:34am UTC](https://forum.djangoproject.com/t/how-do-i-access-redis-values-of-keys-stored-from-elsewhere/19929 "2023-03-31T09:34:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [March 31, 2023, 9:34am UTC](https://forum.djangoproject.com/t/how-do-i-access-redis-values-of-keys-stored-from-elsewhere/19929/1 "2023-03-31T09:34:25Z")

</div>

So I’m inserting data into a redis url in an external script via a cron.

I want to read this in Django 4.1.7.

A simple `print("name = ", cache.get('name'))` doesn’t work.

Because if I do in my views.py

```auto
cache.set('name', 'John')
print("name = ", cache.get('name'))

```

works as it stores it in the Redis cache as :

```auto
["somePrefix:1:name","string"]
���John�.

```

So how do I get just **name** stored from elsewhere ?

I am using upstash.

---

<div class="post-metadata">

**Author:** ![leandrodesouzadev](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/leandrodesouzadev/32/8981_2.png) [@leandrodesouzadev](https://forum.djangoproject.com/u/leandrodesouzadev)\
**Post date:** [March 31, 2023, 10:45am UTC](https://forum.djangoproject.com/t/how-do-i-access-redis-values-of-keys-stored-from-elsewhere/19929/2 "2023-03-31T10:45:32Z")

</div>

Looking up the source code from django, i had found the `default_key_func` on [django/core/cache/backends/base.py](https://github.com/django/django/blob/main/django/core/cache/backends/base.py#L31) this function is used by the `BaseBackend` class also defined later on that file. This is the base class for all backends, and on the `RedisBackend` defined on [django/core/cache/backends/redis.py](https://github.com/django/django/blob/main/django/core/cache/backends/redis.py#L189) on the `set` method, it will make use of this key.

This function will use the `make_default_key` function that creates a namespace around the key, so on that case `name` can be something like: `1:name` where `1` prefix is the version (this parameter is the default when you call set, without the `version` argument), considering that the `KEY_PREFIX` is the default (a empty string).  
You can provide a custom function to make the key, this is documented [here](https://docs.djangoproject.com/en/4.1/topics/cache/#cache-arguments)

---

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [March 31, 2023, 12:27pm UTC](https://forum.djangoproject.com/t/how-do-i-access-redis-values-of-keys-stored-from-elsewhere/19929/3 "2023-03-31T12:27:11Z")

</div>

For the time-being to make it work I did in my views.py file `r = redis.Redis(...)`
