question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support for REJSON

See original GitHub issue

Hello @luin ,

Do you plan to add the support of the command for REJSON product from RedisLab ?

For now I using call method, it works fine but if we would have them included it would be great.

Thanks

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

5reactions
nidomirocommented, Nov 9, 2020

I had the same problem while searching for a lib to handle RedisJson. The call method was renamed. Here is a working example:

import * as IORedis from "ioredis";
const redis = new IORedis();

function printWithType(v: unknown) {
  console.log("---")
  console.log("Type: ", typeof v)
  console.log("Value: ", v)
  console.log("---")
}

redis.send_command("JSON.SET", "my:key", ".",  '{"id": "abc", "groups": ["A", "B", "C"]}')
  .then(printWithType)
  .catch(e => (console.error(e)))

redis.send_command("JSON.GET", "my:key")
  .then(printWithType)
  .catch(e => (console.error(e)))

redis.send_command("JSON.GET", "my:key", ".id")
  .then(printWithType)
  .catch(e => (console.error(e)))

redis.send_command("JSON.GET", "my:key", ".groups")
  .then(printWithType)
  .catch(e => (console.error(e)))

The output is:

---
Type:  string
Value:  OK
---
---
Type:  string
Value:  {"id":"abc","groups":["A","B","C"]}
---
---
Type:  string
Value:  "abc"
---
---
Type:  string
Value:  ["A","B","C"]
---
1reaction
OmarOmeiricommented, Jul 28, 2021
redis.send_command("JSON.SET", "my:key", ".",  '{"id": "abc", "groups": ["A", "B", "C"]}')
  .then(printWithType)
  .catch(e => (console.error(e)))

redis.send_command("JSON.GET", "my:key")
  .then(printWithType)
  .catch(e => (console.error(e)))

redis.send_command("JSON.GET", "my:key", ".id")
  .then(printWithType)
  .catch(e => (console.error(e)))

redis.send_command("JSON.GET", "my:key", ".groups")
  .then(printWithType)
  .catch(e => (console.error(e)))

Why do I get errors? all commands are unknown for me. using the same code you provided with Node 16.x?

ReplyError: ERR unknown command 'JSON.SET'
    at parseError (E:\Documents\CODE\WebDev\Lullo\backend\src\node_modules\redis-parser\lib\parser.js:179:12)
    at parseType (E:\Documents\CODE\WebDev\Lullo\backend\src\node_modules\redis-parser\lib\parser.js:302:14) {
  command: {
    name: 'JSON.SET',
    args: [ 'my:key', '.', '{"id": "abc", "groups": ["A", "B", "C"]}' ]
  }
}
ReplyError: ERR unknown command 'JSON.GET'
    at parseError (E:\Documents\CODE\WebDev\Lullo\backend\src\node_modules\redis-parser\lib\parser.js:179:12)
    at parseType (E:\Documents\CODE\WebDev\Lullo\backend\src\node_modules\redis-parser\lib\parser.js:302:14) {
  command: { name: 'JSON.GET', args: [ 'my:key' ] }
}
ReplyError: ERR unknown command 'JSON.GET'
    at parseError (E:\Documents\CODE\WebDev\Lullo\backend\src\node_modules\redis-parser\lib\parser.js:179:12)
    at parseType (E:\Documents\CODE\WebDev\Lullo\backend\src\node_modules\redis-parser\lib\parser.js:302:14) {
  command: { name: 'JSON.GET', args: [ 'my:key', '.id' ] }
}
ReplyError: ERR unknown command 'JSON.GET'
    at parseError (E:\Documents\CODE\WebDev\Lullo\backend\src\node_modules\redis-parser\lib\parser.js:179:12)
    at parseType (E:\Documents\CODE\WebDev\Lullo\backend\src\node_modules\redis-parser\lib\parser.js:302:14) {
  command: { name: 'JSON.GET', args: [ 'my:key', '.groups' ] }
}

UPDATE

Figured it out. Apparently my connection was not established. When running the commands. This made it work for me:

import Redis from 'ioredis';

const redis = new Redis('redis://<user>:<password>@redis-service.com:6379/');

redis.connect(() => {
  function printWithType(v: unknown) {
    console.log('---');
    console.log('Type: ', typeof v);
    console.log('Value: ', v);
    console.log('---');
  }

  redis.send_command('JSON.SET', 'my:key', '.', '{"id": "abc", "groups": ["A", "B", "C"]}')
    .then(printWithType)
    .catch((e) => (console.error(e)));

  redis.send_command('JSON.GET', 'my:key')
    .then(printWithType)
    .catch((e) => (console.error(e)));

  redis.send_command('JSON.GET', 'my:key', '.id')
    .then(printWithType)
    .catch((e) => (console.error(e)));

  redis.send_command('JSON.GET', 'my:key', '.groups')
    .then(printWithType)
    .catch((e) => (console.error(e)));
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

RedisJSON | Redis
The RedisJSON module provides JSON support for Redis. RedisJSON lets you store, update, and retrieve JSON values in a Redis database, similar to...
Read more >
JSON with Redis in memory Database - YouTube
Without rejson module the redis json support will not be there. In this video, I'm using python redis to explain how to use...
Read more >
does rejson in redis support complex get query?
No - ReJSON does not support complex query logic. What you could do is couple it (in the application) with RediSearch ...
Read more >
rejson - Go Packages
Go-ReJSON is a Go client for ReJSON redis module ... Note: Currently, go-ReJSON only support redislabs/rejson with version <=1.0.8.
Read more >
rejson - PyPI
rejson -py is a package that allows storing, updating and querying objects as JSON documents in a Redis database that is extended with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found