小编Ian*_*ers的帖子

如何在Node.js中解码/解压缩来自memcached支持的Rails缓存(Dalli gem)的值

我有一个Rails应用程序,通过Dalli gem(https://github.com/mperham/dalli)缓存memcached中的数据.

我想从Node.js读取此缓存的内容.我正在使用mc模块与Node.js中的memcached进行交互.

我遇到的问题是编码和压缩.Dalli使用Zlib::Deflate.deflate(data)(https://github.com/mperham/dalli/blob/master/lib/dalli/compressor.rb).当我尝试从Node.js充气时,我尝试使用zlib模块进行充气时出错:

{ [Error: incorrect header check] errno: -3, code: 'Z_DATA_ERROR' }
Run Code Online (Sandbox Code Playgroud)

这是相关的Ruby/Rails代码:

config.cache_store = :dalli_store, memcached_server, {compress: true}
Run Code Online (Sandbox Code Playgroud)

以及相关的Node.js代码:

client = new Memcached.Client(MEMCACHED_HOSTNAME, Memcached.Adapter.raw);


client.get(key, function (err, response) {
  var data = response[key];

  zlib.inflate(data.buffer, function (err, buf) {
    console.log(err, buf);
  });
});
Run Code Online (Sandbox Code Playgroud)

从memcached的字符串值返回的缓冲区如下所示:

'\u0004\b[\u0015i\u0006i\u0007i\bi\ti\ni\u000bi\fi\ri\u000ei\u000fi\u0010i\u0011i\u0012i\u0014i\u0015i\u0016'

膨胀后我期待的价值如下: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17]

ruby caching ruby-on-rails zlib node.js

13
推荐指数
1
解决办法
807
查看次数

CSS媒体查询捕获高分辨率手机,但不是低分辨率平板电脑

我一直min-width: 600px在CSS媒体查询中使用断点.我的理由是,在600px及以上我会捕捉平板电脑设备(Kindle Fire,iPad等),600px以下会捕获所有手机设备.

事实证明,虽然iPhone的像素增加了一倍,但仍然报告为320px x 480px,但有大量Android手机的分辨率如700px x 1280px.问题是,如何在不给它们提供类似平板电脑的界面的情况下捕获这些设备?

通常情况下,我只是让内容响应设备的像素分辨率,然而,4.3英寸屏幕上的1280px布局看起来并不合适,特别是因为我的应用处理了大量的表单元素,这些都是在手机上你希望跨越整个宽度,但在平板电脑或台式机上却没有.

css mobile web-applications mobile-website media-queries

6
推荐指数
1
解决办法
2980
查看次数

passport.js成功验证没有调用next()

我使用passport.js进行身份验证.看来,在成功验证后,护照不会打电话next(),所以我的Express路线永远不会被执行.对于我实现的两种身份验证策略,我都看到了这种行为.

app.js

app.use(passport.initialize());
passport.use(authentication.local);
passport.use(authentication.bearer);

routes.setup(app, passport);
Run Code Online (Sandbox Code Playgroud)

routes.js

function setup (app, passport) {
  // routes.authentication.token not called, despite successful authentication.
  app.post('/authentication/token', passport.authenticate('local'), 
      routes.authentication.token);
}
Run Code Online (Sandbox Code Playgroud)

authentication.js

var local = new LocalStrategy(
  {
    usernameField: 'email',
    passwordField: 'password'
  },

  function (email, password, done) {
    var user = new User({ email: email });

    user.fetch({
      success: function (user) {
        if (bcrypt.compareSync(password, user.get('encryptedPassword'))) {
          // This line shows in the console, but the route after is never executed.
          console.log("LocalStrategy success!");
          done(null, user); // Tell …
Run Code Online (Sandbox Code Playgroud)

javascript authentication node.js passport.js

5
推荐指数
1
解决办法
1726
查看次数