title: FastAPI with aiocache and Redis Couldn't set databases.backends.postgres.Record object
body: <p>I'm trying to implement Redis on my endpoint using the aiocache library.
  The first test I did with aiocache I used @cache without indicating any other service and everything worked. But when I tried to use Redis I see this error (the endpoint still returns the request)</p>
  <pre><code>ERROR:    Couldn't set [&lt;databases.backends.postgres.Record object at 0x7fb9f01d86a0&gt;, &lt;databases.backends.postgres.Record object at 0x7fb9f01d88b0&gt;, &lt;databases.backends.postgres.Record object at 0x7fb9f01d8a60&gt;] in key app.api.authorget_authors()[], unexpected error
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.8/site-packages/aiocache/decorators.py&quot;, line 144, in set_in_cache
      await self.cache.set(key, value, ttl=self.ttl)
    File &quot;/usr/local/lib/python3.8/site-packages/aiocache/base.py&quot;, line 61, in _enabled
      return await func(*args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/aiocache/base.py&quot;, line 45, in _timeout
      return await asyncio.wait_for(func(self, *args, **kwargs), timeout)
    File &quot;/usr/local/lib/python3.8/asyncio/tasks.py&quot;, line 483, in wait_for
      return fut.result()
    File &quot;/usr/local/lib/python3.8/site-packages/aiocache/base.py&quot;, line 75, in _plugins
      ret = await func(self, *args, **kwargs)
    File &quot;/usr/local/lib/python3.8/site-packages/aiocache/base.py&quot;, line 265, in set
      ns_key, dumps(value), ttl=self._get_ttl(ttl), _cas_token=_cas_token, _conn=_conn
    File &quot;/usr/local/lib/python3.8/site-packages/aiocache/serializers/serializers.py&quot;, line 140, in dumps
      return json.dumps(value)
  TypeError: &lt;databases.backends.postgres.Record object at 0x7fb9f01d8a60&gt; is not JSON serializable
  </code></pre>
  <p>The method is:</p>
  <pre class="lang-py prettyprint-override"><code>@authors.get(&quot;/&quot;, response_model=List[AuthorOut])                                                                                                                                                                                        
  @cached(                                                                                                
       ttl=100,                                                                                            
       cache=Cache.REDIS,
       endpoint=&quot;X.X.X.X&quot;, #my local ip
       serializer=JsonSerializer(),
       port=6379,
       namespace=&quot;main&quot;,
       #key=&quot;key&quot;,
   )
  async def get_authors():
     return await db_manager.get_all_authors() 
  </code></pre>
  <p>The whole environment is based on docker, 2 containers, 1 FastApi, 1 PostgreSQL and 1 Redis.</p>
  <p>It seems evident that there is a problem with the object returned by the endpoint, so I ask you how can I pass such a complex object to Redis?</p>
  <p>Following the aiochace documentation I have tried all the serializers present but without success.</p>
  <p>My docker-compose</p>
  <pre><code>version: '3.7'
  
  services:
    book_service:
      build: ./book-service
      command: uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
      volumes:
        - ./book-service/:/app/
      ports:
        - 8001:8000
      environment:
        - DATABASE_URI=postgresql://book_db_username:book_db_password@book_db/book_db_dev
        - AUTHOR_SERVICE_HOST_URL=http://author_service:8000/api/v1/authors/
      depends_on:
        - book_db
  
    book_db:
      image: postgres:12.1-alpine
      volumes:
        - postgres_data_book:/var/lib/postgresql/data/
      environment:
        - POSTGRES_USER=book_db_username
        - POSTGRES_PASSWORD=book_db_password
        - POSTGRES_DB=book_db_dev
    
    author_service:
      build: ./author-service
      command: uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
      volumes:
        - ./author-service/:/app/
      ports:
        - 8002:8000
      environment:
        - DATABASE_URI=postgresql://author_db_username:author_db_password@author_db/author_db_dev
      depends_on:
        - author_db
  
    author_db:
      image: postgres:12.1-alpine
      volumes:
        - postgres_data_author:/var/lib/postgres/data
      environment:
        - POSTGRES_USER=author_db_username
        - POSTGRES_PASSWORD=author_db_password
        - POSTGRES_DB=author_db_dev
  
    nginx:
      image: nginx:latest
      ports:
        - &quot;8080:8080&quot;
      volumes:
        - ./nginx_config.conf:/etc/nginx/conf.d/default.conf
      depends_on:
        - author_service
        - book_service
  
    redis:
      image: redis:3.2-alpine
      volumes:
        #      - redis_data:/data
        - ./redis.conf:/usr/local/etc/redis/redis.conf
      command: redis-server /usr/local/etc/redis/redis.conf
      ports:
        - 6379:6379
  
      networks:
        node_net:
          ipv4_address: 172.28.1.4
  
  networks:
    node_net:
      ipam:
        driver: default
        config:
          - subnet: 172.28.0.0/16
  
  volumes:
    postgres_data_book:
    postgres_data_author:
    redis_data:
  </code></pre>