javascript 如何在Redis中执行持久化存储?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10909282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:26:54  来源:igfitidea点击:

How to perform Persistence Store in Redis?

javascriptredis

提问by Jai Shakthi

after shutting down the redis server, the values stored using set is destroyed, here i found the way to use the persistence store, anyone help me, how to achieve that using javascript ?

关闭 redis 服务器后,使用 set 存储的值被销毁,在这里我找到了使用持久性存储的方法,任何人都可以帮助我,如何使用 javascript 实现?

I wanna store some values from clients in redis db, and have to use that value in other clients.

我想在 redis db 中存储来自客户端的一些值,并且必须在其他客户端中使用该值。

回答by Didier Spezia

You need to configure your Redis server to support a persistency mechanism. This configuration is stored in a file which is given as a parameter on the redis-server command line.

您需要配置 Redis 服务器以支持持久性机制。此配置存储在一个文件中,该文件在 redis-server 命令行上作为参数给出。

Here is the default file for Redis 2.4: https://github.com/antirez/redis/blob/2.4/redis.conf

这是 Redis 2.4 的默认文件:https: //github.com/antirez/redis/blob/2.4/redis.conf

Actually two different persistency mechanisms are provided: snapshotting (RDB) and append-only files (AOF). You will find a full explanation here: http://redis.io/topics/persistence

实际上提供了两种不同的持久性机制:快照(RDB)和仅附加文件(AOF)。你会在这里找到完整的解释:http: //redis.io/topics/persistence

The easiest mechanism is snapshotting (RDB). It can be activated by defining save, dbfilenameand dirparameters in the configuration file.

最简单的机制是快照 (RDB)。它可以通过在配置文件中定义savedbfilenamedir参数来激活。

To activate RDB without stopping the Redis server, you can use the following command from the Redis client:

要在不停止 Redis 服务器的情况下激活 RDB,您可以从 Redis 客户端使用以下命令:

> config set save "300 1"

It will configure RDB to dump everything every 5 min (to be adapted to your own situation).

它将配置 RDB 每 5 分钟转储一次(以适应您自己的情况)。

Please note that you are supposed to use the shutdowncommand to stop a Redis server. The default behavior is to generate a last snapshot before stopping. The dump file is loaded in memory when Redis starts again.

请注意,您应该使用shutdown命令来停止 Redis 服务器。默认行为是在停止之前生成最后一个快照。当 Redis 再次启动时,转储文件会加载到内存中。

Should you need to extract data from the dump file (when Redis is offline), you have an excellent Python package at https://github.com/sripathikrishnan/redis-rdb-tools

如果您需要从转储文件中提取数据(当 Redis 离线时),您可以在https://github.com/sripathikrishnan/redis-rdb-tools 上找到一个出色的 Python 包