简体   繁体   English

我应该保持我的Redis连接持久吗?

[英]Should I keep my redis connection persistent?

I'm considering using redis as a key value store for my api application. 我正在考虑将redis用作我的api应用程序的键值存储。 The api basically only needs one client connection to the redis. api基本上只需要一个客户端连接到redis。 What I'm not sure is that should I keep the connection open forever? 我不确定是否应该永远保持连接打开状态? Or should I only open the connection when I need to set or get values from redis? 还是只在需要设置或从Redis获取值时才打开连接?

One could think that opening the connection is an expensive operation, so in that sense one should prefer forever connections. 有人会认为打开连接是一项昂贵的操作,因此从这个意义上讲,应该永远喜欢连接。 On the other hand, keeping the connection always open is not as secure as opening it only when you need it. 另一方面,保持连接始终打开不如仅在需要时打开连接安全。 And also, having long open connections open could result in timeouts. 而且,长时间打开连接可能会导致超时。 Does redis try to reconnect if the connection fails for some reason? 如果由于某种原因连接失败,redis是否会尝试重新连接? How well does redis handle long open connections? Redis如何处理长时间开放的连接? Any help is appreciated! 任何帮助表示赞赏!

Redis auto-connection depends on the redis-client that you are using. Redis自动连接取决于您使用的Redis客户端。 For example, if you use ioredis , it will automatically try reconnect when the connection to Redis is lost except when the connection is closed manually. 例如,如果使用ioredis ,则在与Redis的连接丢失时(除非手动关闭),它将自动尝试重新连接。

Source: https://github.com/luin/ioredis#auto-reconnect 资料来源: https : //github.com/luin/ioredis#auto-reconnect

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Azure Redis 集群时,我应该在我的 redis 客户端中使用集群连接吗? - Should i use cluster connection in my redis client when using Azure Redis Cluster? 是否应该为每个连接创建一个新的Redis客户端? - Should I create a new Redis client for each connection? 我该如何保持出版物的反应? - How should I keep my publication reactive? 在页面上重新加载表单后,如何编写JavaScript cookie以保持数据持久性? - How can I write JavaScript cookies to keep the data persistent after page reloads on my form? 我可以将令牌保留在受保护的路由上吗? - Can I keep the token persistent on protected routes? 即使在页面刷新后,如何保持 Websocket 连接持久? - How keep a Websocket connection persistent, even after page refresh? 我应该迁移到 Manifest v3 吗,因为我的扩展的大部分功能都依赖于持久的背景 - Should I migrate to Manifest v3 because most of the features of my extension depends on persistent background 我应该对我的地址解析API密钥保密吗? - should I keep my geocode api key a secret? 我应该如何在Redis中存储该对象? - How should I store this object in Redis? (Express js)我应该如何在我的路由器中使用另一个模块? (我不断收到未定义的参考错误) - (Express js) How should I use another module in my router? (I keep getting undefined reference error)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM