memcache 错误键中存在非法字符(Ruby 1.8.7 / Rails 2.3.9)

发布于 2024-11-09 03:55:46 字数 813 浏览 0 评论 0原文

我在我的一个 Rails 应用程序 [Ruby 1.8.7 + Rails 2.3.9] 中遇到以下错误,

A ArgumentError occurred in home#dashboard:
 illegal character in key "dashboard_prod:views/reports/1050 - 097"
 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/activesupport-2.3.9/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb:643:in `get_server_for_key'

我用 google 搜索并发现有人遇到类似的问题: http://www.coffeepowered.net/page/2/

在该页面上提到,这应该有效:

class ActionController::Caching::Actions::ActionCachePath

    def path

        @cached_path ||= Digest::SHA1.hexdigest(@path)

    end

end

但我不确定应该在哪里输入此内容。所以我有两个问题:

  1. 如何解决手头的问题
  2. 我应该在哪里编写像上面这样的代码,我们要重写一些标准类或 Gem 中定义的类。

任何帮助将不胜感激。

I am getting the following error in one of my rails app [Ruby 1.8.7 + Rails 2.3.9]

A ArgumentError occurred in home#dashboard:
 illegal character in key "dashboard_prod:views/reports/1050 - 097"
 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/activesupport-2.3.9/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb:643:in `get_server_for_key'

I googled and found that someone had similar problem at: http://www.coffeepowered.net/page/2/

on that page it is mentioned that, this should work:

class ActionController::Caching::Actions::ActionCachePath

    def path

        @cached_path ||= Digest::SHA1.hexdigest(@path)

    end

end

But I am not sure where should I type this. So I have two questions:

  1. How to solve problem at hand
  2. Where should I write the code like the above where we are overriding some standard class or class defined in a Gem.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

予囚 2024-11-16 03:55:46

我认为您发现的帖子建议您使用该代码创建一个猴子补丁。使用这些内容在 Rails.root + 'lib/' 下创建一个文件,并确保它在 ActionController (这应该是默认值)之后加载。该补丁将覆盖 ActionController 的默认代码。

你肯定想要这样的东西——我总是确保我的内存缓存密钥经过哈希处理。这使它们的调试变得更加困难,但它可以防止出现此类问题,并且当有人创建对于 memcached 来说太长的密钥时,也可以防止出现密钥长度溢出错误。

I think the post you found is suggesting you create a monkey patch with that code. Create a file under Rails.root + 'lib/' with those contents, and make sure it loads after ActionController (which should be the default). The patch will override ActionController's default code.

You definitely want something like that--I always ensure my memcached keys are hashed. It makes them a little more difficult to debug, but it protects against problems like this and also key-length overflow errors when someone creates a key that's too long for memcached.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文