Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@redis/json
Advanced tools
This package provides support for the [RedisJSON](https://redis.io/docs/stack/json/) module, which adds JSON as a native data type to Redis. It extends the [Node Redis client](https://github.com/redis/node-redis) to include functions for each of the Redi
@redis/json is an npm package that provides a client for Redis' JSON capabilities, allowing you to store, retrieve, and manipulate JSON documents directly within Redis. This package leverages the RedisJSON module, which is designed to handle JSON data efficiently.
Set JSON Data
This feature allows you to set JSON data in a Redis key. The code sample demonstrates how to connect to a Redis client, set a JSON object under a specific key, and then disconnect from the client.
const { createClient } = require('@redis/json');
async function setJsonData() {
const client = createClient();
await client.connect();
await client.json.set('user:1', '$', { name: 'John Doe', age: 30, city: 'New York' });
await client.disconnect();
}
setJsonData();
Get JSON Data
This feature allows you to retrieve JSON data from a Redis key. The code sample shows how to connect to a Redis client, get the JSON object stored under a specific key, log the data, and then disconnect from the client.
const { createClient } = require('@redis/json');
async function getJsonData() {
const client = createClient();
await client.connect();
const userData = await client.json.get('user:1');
console.log(userData);
await client.disconnect();
}
getJsonData();
Update JSON Data
This feature allows you to update specific fields within a JSON object stored in Redis. The code sample demonstrates how to connect to a Redis client, update the 'age' field of the JSON object under a specific key, and then disconnect from the client.
const { createClient } = require('@redis/json');
async function updateJsonData() {
const client = createClient();
await client.connect();
await client.json.set('user:1', '$.age', 31);
await client.disconnect();
}
updateJsonData();
Delete JSON Data
This feature allows you to delete JSON data from a Redis key. The code sample shows how to connect to a Redis client, delete the JSON object stored under a specific key, and then disconnect from the client.
const { createClient } = require('@redis/json');
async function deleteJsonData() {
const client = createClient();
await client.connect();
await client.json.del('user:1');
await client.disconnect();
}
deleteJsonData();
ioredis is a robust, full-featured Redis client for Node.js. While it does not natively support JSON operations, it can be used in conjunction with RedisJSON to achieve similar functionality. ioredis is known for its performance and support for advanced Redis features like clustering and sentinel.
redis is the official Node.js client for Redis. Like ioredis, it does not have built-in support for JSON operations but can be used with RedisJSON. It is a straightforward and reliable client for basic Redis operations.
node-redis is another popular Redis client for Node.js. It provides a simple and efficient way to interact with Redis but lacks native JSON support. It can be paired with RedisJSON for handling JSON data.
This package provides support for the RedisJSON module, which adds JSON as a native data type to Redis. It extends the Node Redis client to include functions for each of the RedisJSON commands.
To use these extra commands, your Redis server must have the RedisJSON module installed.
For a complete example, see managing-json.js
in the Node Redis examples folder.
The JSON.SET
command stores a JSON value at a given JSON Path in a Redis key.
Here, we'll store a JSON document in the root of the Redis key "mydoc
":
import { createClient } from 'redis';
...
await client.json.set('noderedis:jsondata', '$', {
name: 'Roberta McDonald',
pets: [
{
name: 'Rex',
species: 'dog',
age: 3,
isMammal: true
},
{
name: 'Goldie',
species: 'fish',
age: 2,
isMammal: false
}
]
});
For more information about RedisJSON's path syntax, check out the documentation.
With RedisJSON, we can retrieve all or part(s) of a JSON document using the JSON.GET
command and one or more JSON Paths. Let's get the name and age of one of the pets:
const results = await client.json.get('noderedis:jsondata', {
path: [
'.pets[1].name',
'.pets[1].age'
]
});
results
will contain the following:
{ '.pets[1].name': 'Goldie', '.pets[1].age': 2 }
RedisJSON includes commands that can atomically update values in a JSON document, in place in Redis without having to first retrieve the entire document.
Using the JSON.NUMINCRBY
command, we can update the age of one of the pets like this:
await client.json.numIncrBy('noderedis:jsondata', '.pets[1].age', 1);
And we can add a new object to the pets array with the JSON.ARRAPPEND
command:
await client.json.arrAppend('noderedis:jsondata', '.pets', {
name: 'Robin',
species: 'bird',
age: 1,
isMammal: false
});
FAQs
This package provides support for the [RedisJSON](https://redis.io/docs/stack/json/) module, which adds JSON as a native data type to Redis. It extends the [Node Redis client](https://github.com/redis/node-redis) to include functions for each of the Redi
The npm package @redis/json receives a total of 411,969 weekly downloads. As such, @redis/json popularity was classified as popular.
We found that @redis/json demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.