Ruby守护进程为临时Ruby实例保持对象活动 [英] Ruby daemon process to keep objects alive for transient Ruby instances

查看:97
本文介绍了Ruby守护进程为临时Ruby实例保持对象活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby是否提供一种机制来在运行中的Ruby进程之间共享变量(更重要的是,类对象和我认为对此有用的任何其他数据抽象)?

Does Ruby offer a mechanism to share variables (more importantly, class objects and any other data abstractions I deem useful for that matter) between different running Ruby processes?

例如,如果我有一个实例化,初始化并仔细调整为某个状态的类,那么我希望该状态可以全天候供我本来可以独立运行的所有Ruby和Irb全局使用,而不用最初使用的进程的生命周期

For example if I have a class instantiated, initialized and carefully tuned to a certain state, I want that state to sort of globally be available to all my otherwise independent Ruby and Irb runs throughout the day, outliving the lifetime of the process that initially used it.

我正在考虑有效解决是要创建一个微型Ruby脚本,仅充当我选择的持久性对象和变量一天的维护者,并使用 daemons gem 或类似名称对其进行守护进程。早上1时开始设置,晚上一切都结束时拆除。

One scenario I'm now considering to effectively address this problem is to create a micro Ruby script acting merely as a keeper of my chosen persistent objects and variables for a day, and daemonize it with the daemons gem or similar. Set-up 1st in the morning, tear-down at night at the end of all things.

在一天当中,另一个Ruby程序的许多实例(其中包含我的实际的业务逻辑-会来来去去,但仍然能够使用和操作在上面的守护进程中保持活动的所选对象。

Throughout the day many instances of another Ruby program--the one containing my actual business logic--would come and go yet be able to use and manipulate my chosen objects kept alive in the daemon process above.

我应该研究如何序列化复杂对象对象到磁盘? (实际上更喜欢RAM而不是磁盘,因为无论如何它都是临时的,并且重新创建它只花费很多时间)

Should I be studying how to serialize complex objects to disk? (actually prefer RAM not disk since it's temporary for a period anyway, and recreating it only costs much time)

推荐答案

可能正在寻找类似 memcache 宝石)或 redis 宝石)。

You're probably looking for something like memcache (Gem) or redis (Gem).

您可能对 redis-对象

这篇关于Ruby守护进程为临时Ruby实例保持对象活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆