首页 > 数据库 >Using Redis with FastAPI

Using Redis with FastAPI

时间:2023-12-06 22:57:01浏览次数:39  
标签:__ Redis redis https FastAPI Using com

Using Redis with FastAPI

https://developer.redis.com/develop/python/fastapi/

https://github.com/fanqingsong/fastapi-redis-tutorial

FastAPI is a Python web framework based on the Starlette microframework. With deep support for asyncio, FastAPI is indeed very fast. FastAPI also distinguishes itself with features like automatic OpenAPI (OAS) documentation for your API, easy-to-use data validation tools, and more.

Of course, the best way to make your FastAPI service even faster is to use Redis. Unlike most databases, Redis excels at low-latency access because it's an in-memory database.

In this tutorial, we'll walk through the steps necessary to use Redis with FastAPI. We're going to build IsBitcoinLit, an API that stores Bitcoin sentiment and price averages in Redis Stack using a timeseries data structure, then rolls these averages up for the last three hours.

 

aioredis

https://aioredis.readthedocs.io/en/latest/getting-started/

import asyncio

import aioredis


async def main():
    redis = aioredis.from_url("redis://localhost")
    await redis.set("my-key", "value")
    value = await redis.get("my-key")
    print(value)


if __name__ == "__main__":
    asyncio.run(main())

 

redis timeseries api

https://redis.io/commands/ts.create/

 

Redis 数据类型

https://www.runoob.com/redis/redis-data-types.html

 

background task

https://fastapi.tiangolo.com/tutorial/background-tasks/

 

标签:__,Redis,redis,https,FastAPI,Using,com
From: https://www.cnblogs.com/lightsong/p/17880721.html

相关文章

  • JAVA操作Redis工具类
    importlombok.extern.slf4j.Slf4j;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.data.redis.core.RedisTemplate;importorg.springframework.stereotype.Component;importorg.springframework.util.CollectionUtils;im......
  • pip:Unable to create process using ‘“‘错误
    学习自:完美解决:执行pip时Unabletocreateprocessusing‘“‘错误(详细流程)-CSDN博客1、背景1)在一台新电脑上安装了python3.6;2)将python3.6和python3.6的Scripts目录都加入到了环境变量中;3)cmd命令行中输入python3可以顺利进入Python控制台;4)输入pip3报错Unabletocreatepro......
  • using的使用
    文章参考:爱编程的大丙(subingwen.cn)1.C++98在C++11之前,using有两种用法:用来声明要使用的命名空间:usingnamesapcestd;当子类重载父类的同名成员函数时,通过using继承父类的同名函数。#include<iostream>usingnamespacestd;classPerson{public:void......
  • Spring Boot整合Redis实现订单超时处理
    文章目录为什么使用Redis?准备工作创建订单实体类存储订单到Redis设置订单超时监控订单超时订阅订单超时消息总结......
  • 68.删除redis中whiteKey开头的值
    importredis#Redis连接信息redis_host='hostname'redis_port=6379redis_password='passwd'redis_db=5#选择数据库5#连接到Redis服务器redis_client=redis.StrictRedis(host=redis_host,port=redis_port,password=redis_password,db=red......
  • 67.redis批量写入ip地址脚本
    #要使用Python脚本连接到Redis主机、选择数据库、并执行设置操作,你可以使用redis库。请确保在运行脚本之前安装了该库(可以通过运行pipinstallredis安装)。importredisimportre#Redis连接信息redis_host='hostname'redis_port=6379redis_password='passwd'redi......
  • fastapi的两种启动方式
     代码文件中启动if__name__=='__main__':uvicorn.run('test:app')#其中test为当前py文件,app为FastAPI的实例对象,这样启动默认为http://127.0.0.1:8000,可自行配置host,port,workers,reload等参数。终端启动#cd到启动文件同目录#终端执行uvicorntest:app--reloa......
  • Redis
    Redis笔记一、常用命令登录redis-cliauthpassword二、数据类型stringString的数据结构为简单动态字符串(SimpleDynamicString,缩写SDS)。是可以修改的字符串,内部结构上类似于Java的ArrayList,采用分配冗余空间的方式来减少内存的频繁分配。动态大小:SDS可以根据存储的字......
  • Redis集群
    RedisSentinel:什么是Sentinel?有什么用?Sentinel如何检测节点是否下线?主观下线与客观下线的区别?Sentinel是如何实现故障转移的?为什么建议部署多个sentinel节点(哨兵集群)?Sentinel如何选择出新的master(选举机制)?如何从Sentinel集群中选择出Leader?Sentinel可以防......
  • 基于社区电商的Redis缓存架构-库存模块缓存架构(下)
    基于缓存分片的下单库存扣减方案将商品进行数据分片,并将分片分散存储在各个Redis节点中,那么如何计算每次操作商品的库存是去操作哪一个Redis节点呢?我们对商品库存进行了分片存储,那么当扣减库存的时候,操作哪一个Redis节点呢?通过轮询的方式选择Redis节点,在Redis中通过记录......