使用 Memcached Sinatra 风格的 NoMethodError

发布于 2024-09-04 05:33:44 字数 538 浏览 3 评论 0原文

我刚刚在 Mac 上安装了 Memcached 并更新了我的 Sinatra 应用程序配置,如 Heroku 的 文档中所述,但是当我尝试使用他们指定的基于哈希的语法时,我收到了 NoMethodError

>> CACHE['color'] = 'blue'
>> CACHE['color']

使用显式 getset下面的方法似乎效果很好。

>> CACHE.set('color', 'blue')
>> CACHE.get('color')

如果有必要我可以使用后一种语法,但前者看起来更优雅。我还没有在 Heroku 的环境中测试过这个,因为我希望我使用的任何实现也能在我的本地环境中工作。谢谢!

I've just installed Memcached on my Mac and updated my Sinatra app configuration as described in Heroku's documentation, but I'm getting a NoMethodError when trying to use the hash-based syntax they specify:

>> CACHE['color'] = 'blue'
>> CACHE['color']

Using explicit get and set methods as below seems to work fine.

>> CACHE.set('color', 'blue')
>> CACHE.get('color')

If necessary I can use the latter syntax, but the former seems more elegant. I haven't tested this on Heroku's environment since I'd like whatever implementation I use to work on my local environment as well. Thanks!

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

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

发布评论

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

评论(1

十年不长 2024-09-11 05:33:44

你可以这样做:

class << CACHE
  alias [] get
  alias []= set
end

You could do this:

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