【问题标题】:Implementing a PHP compatible memcache client for node.js为 node.js 实现一个 PHP 兼容的 memcache 客户端
【发布时间】:2011-09-13 09:33:20
【问题描述】:

我正在尝试为 node.js 实现另一个纯 JavaScript 内存缓存客户端。
问题是我必须从多线程内存缓存服务器获取由 PHP Memcache 类设置的密钥,但我无法弄清楚 PHP 如何对这些密钥进行哈希处理。

我找了 Memcache 类手册:
http://www.php.net/manual/en/memcache.ini.php

“memcache.hash_function”是“crc32”,但我仍然不知道如何从 crc32 哈希中确定要设置的服务器。

是否有一些文档或参考资料?
提前致谢。

【问题讨论】:

  • 为什么不用redis,升级PHP代码使用redis?或者,只需在 node.js 中重写 PHP 代码。编写纯 JavaScript 内存缓存客户端同样痛苦,收益明显减少

标签: php node.js memcached


【解决方案1】:

信息将存放在 PECL 中:http://pecl.php.net/package/memcache

要了解详细信息,您很可能需要查看source of the extension

【讨论】:

    【解决方案2】:

    我通过 npm 使用了http://search.npmjs.org/#/memcache。在 node.js 和 php 中运行良好(使用 'memcached' mod 而不是 'memcache')。

    文档很少。您可以使用下面的代码开始。

    var memcache = require('memcache');
    
    var client = new memcache.Client(11211, '127.0.0.1');
    
    client.connect();
    
    client.get('aaa', function(error, result){
    
        console.log(result);
        // all of the callbacks have two arguments.
        // 'result' may contain things which aren't great, but
        // aren't really errors, like 'NOT_STORED'
    
    });
    

    【讨论】:

    • 太棒了!我会尽快尝试的。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 2020-12-22
    • 2014-09-29
    • 2019-09-16
    • 2012-07-10
    相关资源
    最近更新 更多