Redis/获取所有密钥 &来自带有前缀的 redis 值 [英] Redis / Get all keys & values from redis with prefix

查看:67
本文介绍了Redis/获取所有密钥 &来自带有前缀的 redis 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的数据存储在 redis 中.我将它的 guid、createday 和它的大小存储在一个原始数据中.

I store my data in redis. I store in one raw it guid, createday, and it size.

所以我定义如下:

var dbclient1 = db.createClient();
dbclient1.hmset("doc:3743-da23-dcdf-3213", "date", "2015-09-06 00:00:01", "size", "203")
dbclient1.zadd("cache", 32131, "37463-da23-dcdf-3213")

我希望查看我的数据库中的所有文件.所以我尝试以下操作:

I wish to view all my files in my db. So I try the following:

dbclient1.hgetall("doc:*", function (err, res){
        console.log(err)
        console.log(res)
})

但 res 是 undefined.我该怎么做?

but res is undefined. How can I do it?

推荐答案

HGETALL 返回存储在 key 处的哈希的所有字段和值,您不能指定掩码:http://redis.io/commands/hgetall

HGETALL returns all fields and values of the hash stored at key, you can't specify a mask: http://redis.io/commands/hgetall

您可以调用 KEYS doc:* 来获取与您的条件匹配的所有键的列表,然后在循环中获取所有值.

You can call KEYS doc:* to get a list of all keys matching your criteria and then get all values in a loop.

但请在执行此操作之前阅读有关潜在性能影响的部分:http://redis.io/commands/键

But please read a section on potential performance hit before you do that: http://redis.io/commands/keys

这篇关于Redis/获取所有密钥 &来自带有前缀的 redis 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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