如何在node.js中获取所有memcached数据? [英] How to get All memcached data in node.js?

查看:90
本文介绍了如何在node.js中获取所有memcached数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我的目的是当用户关闭浏览器时,用户会话数据应该过期.现在的问题是,我的服务器需要memcached才能正常工作.因此,我想从已关闭浏览器的memcached中删除该特定用户会话.我不想清除所有内存缓存,以便其余用户的会话仍应存在.

First, my purpose is when the user close the browser then the user session data should expire. Now the problem is that, my Server requires memcached to work properly. So, I want to delete that specific user session from memcached who has closed his browser. I dont want to clear all memcached so that the remaining users' session should still exist.

推荐答案

在Memcached中,除非您要使用

In Memcached there is no way to list all keys in a specific namespace unless you want to use some workarounds, and I don't recommend you in production.

一种替代方法是将所有与用户相关的Memcached密钥存储在一个集合中(也存储在memcached中).设置密钥是使用用户ID生成的,因此您始终可以提前知道它的值,并且可以轻松地检索它.

One alternative would be to store all user-related Memcached keys in a set (stored in memcached as well). The set key is generated using the user id, so that you always know in advance its value and you can easily retrieve it.

用户会话结束后,您可以获取包含用户密钥列表的项目,然后删除每个密钥.请记住,包含键列表的键的到期时间应大于任何特定于项目的键.

Once the user session ends, you can fetch the item containing the list of user keys, then delete each key. Keep in mind that the key containing the list of keys should have an expiration greater than any item-specific item.

还值得一提的是, Redis 支持键迭代和默认设置,您可以将其配置为像Memcached.您可能需要尝试一下.

It is also worth mentioning that Redis supports key iteration and sets by default, and you can configure it to work like Memcached. You may want to give it a try.

这篇关于如何在node.js中获取所有memcached数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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