Node.js - clent.hgetall 和 client.hmset 在 Redis 中
Redis 命令通常将输入作为单个字符串或字符串数组作为参数,而回复则以单个字符串或字符串数组的形式发送回。然而,在处理哈希值时,有几个例外。
Node.js 中的 client.hgetall() 函数 - Redis 返回一个以哈希键为键的对象。字符串将以字符串或缓冲区形式返回,具体取决于设置。
client.hmset() 函数向 Redis 提供哈希参数。
语法
client.hmset()
client.hmset(hash, key1, val1, ...keyN, valN, [callback])
client.hgetall()
client.hgetall(hash, callback)
示例 1
创建一个名为 "hmset.js" 的文件,并复制以下代码段。创建文件后,使用命令 "node hmset" 运行此代码,如下面的示例所示 −
// client.hmset Demo Example
// Importing the redis & assert module
const redis = require("redis");
const client = redis.createClient();
client.hmset("hi", "foo", "bar", "hello", "world");输出
There will be no response because the values are stored in Redis DB.
示例 2
// client.hgetall() Demo Example
// Importing the redis & assert module
const redis = require("redis");
const client = redis.createClient();
client.hmset("hi", "foo", "bar", "hello", "world");
client.hgetall("hi", function(err, value) {
console.log(value.foo);
console.log(value.hello);
});输出
C:\home
ode>> node hgetAll.js bar world
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP