diff --git a/docs/queryworkers/redis/index.md b/docs/queryworkers/redis/index.md index 0f45eefdf7..1ec0500324 100644 --- a/docs/queryworkers/redis/index.md +++ b/docs/queryworkers/redis/index.md @@ -43,6 +43,7 @@ Macrometa supports Redis client protocol up to version 6.2. Following table show Our platform has limitation on certan commands. Commands that are mentioned below return different result in some edge cases. - [**SETRANGE**](#setrange) +- [**SINTERSTORE**](#sinterstore) ### SETRANGE @@ -80,3 +81,71 @@ Response of Macrometa platform: Response from Redis server: `(integer) 37` + +### SINTERSTORE + +SINTERSTORE gives the wrong value when an existing key is given as the destination. + + +We will add three different keys with SADD: + +```js +[ + "SADD", + "key_1", + "a", + "b", + "c", + "d" +] +``` + +```js +[ + "SADD", + "key_2", + "c" +] +``` + +```js +[ + "SADD", + "key_3", + "a", + "c", + "e" +] +``` +With SINTERSTORE, we will try to store the set in an existing key: + + +```js +[ + "SINTERSTORE", + "key_2", + "key_1", + "key_2", + "key_3" +] +``` + +Result will be: + +```js +{ + "code": 200, + "result": 0 +} +``` + +Response from Redis server: +`(integer) 1` + +:::note +For Redis SET and SORTED SET datatype commands, using the same keys for the command gives a syntax error. + +For Redis MSET and HMSET commands, using same keys for the command will give an invalid command args error. +::: + + diff --git a/docs/queryworkers/redis/redis-sdks.md b/docs/queryworkers/redis/redis-sdks.md index 9203064dd0..bea921863c 100644 --- a/docs/queryworkers/redis/redis-sdks.md +++ b/docs/queryworkers/redis/redis-sdks.md @@ -9,6 +9,74 @@ import TabItem from '@theme/TabItem'; You can access all the familiar Redis commands using the Macrometa SDK or API. + + +- Step 1. [Install the SDK](../../sdks/install-sdks.md). +- Step 2. Create an instance of the jsc8 +- Step 3. Access Redis commands `client.redis.`. + +```javascript +const jsc8 = require("jsc8"); +client = new jsc8({ + url: "play.paas.macrometa.io", + apiKey: "xxxxx", + fabricName: "_system", +}); + +// We need to create a Redis collection on platform using SDK, Console, or API call +const REDIS_COLLECTION = "testRedisCollection"; + +async function redisExample() { + let response; + // String data type example + // Set string + await client.redis.set("test", "1", REDIS_COLLECTION); + // Get string + response = await client.redis.get("test", REDIS_COLLECTION); + // Response from platform + console.log(response); + + // Sorted set data type example + // Add sorted set + await client.redis.zadd("testZadd", [1, "test"], REDIS_COLLECTION); + // Return range of elements + response = await client.redis.zrange("testZadd", 0, 1, REDIS_COLLECTION); + // Response from platform + console.log(response); + + // List data type example + const listData = ["iron", "gold", "copper"]; + await client.redis.lpush("list", listData, REDIS_COLLECTION); + // Return range of list elements + response = await client.redis.lrange("list", 0, 1, REDIS_COLLECTION); + // Response from platform + console.log(response); + + // Hash data type example + // Set hash + await client.redis.hset( + "games", + {"action": "elden", "driving": "GT7"}, + REDIS_COLLECTION + ); + // Get hash + response = await client.redis.hget("games", "action", REDIS_COLLECTION); + // Response from platform + console.log(response); + + // Sets data type example + await client.redis.sadd("animals", ["dog"], REDIS_COLLECTION); + // Pop sets data + response = await client.redis.spop("animals", 1, REDIS_COLLECTION); + // Response from platform + console.log(response); +} + +redisExample(); + +``` + + - Step 1. [Install the SDK](../../sdks/install-sdks.md). @@ -20,9 +88,12 @@ from c8 import C8Client # Create a connection to GDN client = C8Client(protocol='https', host='play.paas.macrometa.io', port=443, - email='nemo@nautilus.com', password='xxxxx', + apikey="xxxxx", geofabric='_system') +# We need to create redis collection on platform using SDK, Console, or API call +REDIS_COLLECTION = "test_redis_collection" + # String data type example # Set string client.redis.set("test", "1", REDIS_COLLECTION)