Skip to content

Feedback: Redis hashes-code-issue #1495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BibekGITBUH opened this issue May 4, 2025 · 3 comments
Closed

Feedback: Redis hashes-code-issue #1495

BibekGITBUH opened this issue May 4, 2025 · 3 comments
Assignees

Comments

@BibekGITBUH
Copy link

BibekGITBUH commented May 4, 2025

Page https://redis.io/docs/latest/develop/data-types/hashes

import assert from 'assert';
import { createClient } from 'redis';

const client = createClient();
await client.connect();
const res1 = await client.hSet(
'bike:1',
{
'model': 'Deimos',
'brand': 'Ergonom',
'type': 'Enduro bikes',
'price': 4972,
}
)
console.log(res1) // 4

const res2 = await client.hGet('bike:1', 'model')
console.log(res2) // 'Deimos'

const res3 = await client.hGet('bike:1', 'price')
console.log(res3) // '4972'

const res4 = await client.hGetAll('bike:1')
console.log(res4)
/*
{
brand: 'Ergonom',
model: 'Deimos',
price: '4972',
type: 'Enduro bikes'
}
*/

const res5 = await client.hmGet('bike:1', ['model', 'price'])
console.log(res5) // ['Deimos', '4972']

const res6 = await client.hIncrBy('bike:1', 'price', 100)
console.log(res6) // 5072
const res7 = await client.hIncrBy('bike:1', 'price', -100)
console.log(res7) // 4972

const res11 = await client.hIncrBy('bike:1:stats', 'rides', 1)
console.log(res11) // 1
const res12 = await client.hIncrBy('bike:1:stats', 'rides', 1)
console.log(res12) // 2
const res13 = await client.hIncrBy('bike:1:stats', 'rides', 1)
console.log(res13) // 3
const res14 = await client.hIncrBy('bike:1:stats', 'crashes', 1)
console.log(res14) // 1
const res15 = await client.hIncrBy('bike:1:stats', 'owners', 1)
console.log(res15) // 1
const res16 = await client.hGet('bike:1:stats', 'rides')
console.log(res16) // 3
const res17 = await client.hmGet('bike:1:stats', ['crashes', 'owners'])
console.log(res17) // ['1', '1']

.................................................................................................................................

change to :
....................................................................................................................................
// function name in capital dont work in node.js

//update

import assert from 'assert';
import { createClient } from 'redis';

const client = createClient();
await client.connect();
const res1 = await client.hset(
'bike:1',
{
'model': 'Deimos',
'brand': 'Ergonom',
'type': 'Enduro bikes',
'price': 4972,
}
)
console.log(res1) // 4

const res2 = await client.hget('bike:1', 'model')
console.log(res2) // 'Deimos'

const res3 = await client.hget('bike:1', 'price')
console.log(res3) // '4972'

const res4 = await client.hgetall('bike:1')
console.log(res4)
/*
{
brand: 'Ergonom',
model: 'Deimos',
price: '4972',
type: 'Enduro bikes'
}
*/

const res5 = await client.hmget('bike:1', ['model', 'price'])
console.log(res5) // ['Deimos', '4972']

const res6 = await client.hincrby('bike:1', 'price', 100)
console.log(res6) // 5072
const res7 = await client.hincrby('bike:1', 'price', -100)
console.log(res7) // 4972

const res11 = await client.hincrby('bike:1:stats', 'rides', 1)
console.log(res11) // 1
const res12 = await client.hincrby('bike:1:stats', 'rides', 1)
console.log(res12) // 2
const res13 = await client.hincrby('bike:1:stats', 'rides', 1)
console.log(res13) // 3
const res14 = await client.hincrby('bike:1:stats', 'crashes', 1)
console.log(res14) // 1
const res15 = await client.hincrby('bike:1:stats', 'owners', 1)
console.log(res15) // 1
const res16 = await client.hget('bike:1:stats', 'rides')
console.log(res16) // 3
const res17 = await client.hmget('bike:1:stats', ['crashes', 'owners'])
console.log(res17) // ['1', '1']

}

@BibekGITBUH
Copy link
Author

I think in all functions, functions name in uppercase don't work.
Updating those can make user easy to copy and paste then run directly.

@BibekGITBUH BibekGITBUH changed the title Feedback: Redis hashes Feedback: Redis hashes-code-issue May 4, 2025
@dwdougherty
Copy link
Collaborator

dwdougherty commented May 5, 2025

Hi @BibekGITBUH. Thank you for reaching out. Here's what the node-redis documentation has to say:

Redis Commands

There is built-in support for all of the out-of-the-box Redis commands. They are exposed using the raw Redis command names (HSET, HGETALL, etc.) and a friendlier camel-cased version (hSet, hGetAll, etc.):

// raw Redis commands
await client.HSET('key', 'field', 'value');
await client.HGETALL('key');

// friendly JavaScript commands
await client.hSet('key', 'field', 'value');
await client.hGetAll('key');

I ran the example you posted in my Node.js environment with the latest node-redis package installed and got the following output (as expected):

$ node ex.js
4
Deimos
4972
[Object: null prototype] {
  model: 'Deimos',
  brand: 'Ergonom',
  type: 'Enduro bikes',
  price: '4972'
}
[ 'Deimos', '4972' ]
5072
4972
1
2
3
1
1
3
[ '1', '1' ]

@dwdougherty dwdougherty self-assigned this May 5, 2025
@dwdougherty
Copy link
Collaborator

Hi @BibekGITBUH. I see that you acknowledged my comment, so, if you don't mind, I'm going to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants