From e66fa1df50c8e07dc1c7390b76a614b2ed872bec Mon Sep 17 00:00:00 2001 From: Dino Lozina Date: Wed, 21 Dec 2022 10:49:25 +0100 Subject: [PATCH 01/12] Added redis JS examples --- docs/queryworkers/redis/redis-sdks.md | 73 ++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/docs/queryworkers/redis/redis-sdks.md b/docs/queryworkers/redis/redis-sdks.md index 9203064dd0..9b5f57a16d 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 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) From 0cd76e00ec9c89d295456509ff50112f29ed7c79 Mon Sep 17 00:00:00 2001 From: Dino Lozina Date: Wed, 21 Dec 2022 15:38:39 +0100 Subject: [PATCH 02/12] Added additional limitations --- docs/queryworkers/redis/index.md | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/docs/queryworkers/redis/index.md b/docs/queryworkers/redis/index.md index 0f45eefdf7..8b52e4d9c7 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,69 @@ Response of Macrometa platform: Response from Redis server: `(integer) 37` + +### SINTERSTORE + +SINTERSTORE gives wrong value when existing key is given as 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 set in 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 same keys for the command will give a syntax error. +::: + +:::note +For Redis MSET and HMSET commands, using same keys for the command will give a invalid command args error. +::: From 99ae62e1bad58445ee6a5f5512bd45c633bb2aaa Mon Sep 17 00:00:00 2001 From: Dino Lozina <113168755+dlozina-macrometa@users.noreply.github.com> Date: Fri, 23 Dec 2022 10:06:24 +0100 Subject: [PATCH 03/12] Update docs/queryworkers/redis/index.md Co-authored-by: Diana Payton <105658419+diana-macrometa@users.noreply.github.com> --- docs/queryworkers/redis/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/queryworkers/redis/index.md b/docs/queryworkers/redis/index.md index 8b52e4d9c7..617e6eb6ba 100644 --- a/docs/queryworkers/redis/index.md +++ b/docs/queryworkers/redis/index.md @@ -145,5 +145,6 @@ For Redis SET and SORTED SET datatype commands, using same keys for the command ::: :::note -For Redis MSET and HMSET commands, using same keys for the command will give a invalid command args error. +For Redis MSET and HMSET commands, using same keys for the command will give an invalid command args error. + ::: From 666b02a615261dd6cda4a8802a1cb996c194c7c1 Mon Sep 17 00:00:00 2001 From: Dino Lozina <113168755+dlozina-macrometa@users.noreply.github.com> Date: Fri, 23 Dec 2022 10:06:36 +0100 Subject: [PATCH 04/12] Update docs/queryworkers/redis/index.md Co-authored-by: Diana Payton <105658419+diana-macrometa@users.noreply.github.com> --- docs/queryworkers/redis/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/queryworkers/redis/index.md b/docs/queryworkers/redis/index.md index 617e6eb6ba..784b159a96 100644 --- a/docs/queryworkers/redis/index.md +++ b/docs/queryworkers/redis/index.md @@ -84,7 +84,8 @@ Response from Redis server: ### SINTERSTORE -SINTERSTORE gives wrong value when existing key is given as destination. +SINTERSTORE gives the wrong value when an existing key is given as the destination. + We will add three different keys with SADD: From ecf41400c40a0340da7cd922df48ad842a9bd5d8 Mon Sep 17 00:00:00 2001 From: Dino Lozina <113168755+dlozina-macrometa@users.noreply.github.com> Date: Fri, 23 Dec 2022 10:06:44 +0100 Subject: [PATCH 05/12] Update docs/queryworkers/redis/index.md Co-authored-by: Diana Payton <105658419+diana-macrometa@users.noreply.github.com> --- docs/queryworkers/redis/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/queryworkers/redis/index.md b/docs/queryworkers/redis/index.md index 784b159a96..7cc00fbaae 100644 --- a/docs/queryworkers/redis/index.md +++ b/docs/queryworkers/redis/index.md @@ -117,7 +117,8 @@ We will add three different keys with SADD: "e" ] ``` -With SINTERSTORE we will try to store set in existing key: +With SINTERSTORE, we will try to store the set in an existing key: + ```js [ From c3be96a53b142225a2acbde89ef821267a216423 Mon Sep 17 00:00:00 2001 From: Dino Lozina <113168755+dlozina-macrometa@users.noreply.github.com> Date: Fri, 23 Dec 2022 10:06:50 +0100 Subject: [PATCH 06/12] Update docs/queryworkers/redis/index.md Co-authored-by: Diana Payton <105658419+diana-macrometa@users.noreply.github.com> --- docs/queryworkers/redis/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/queryworkers/redis/index.md b/docs/queryworkers/redis/index.md index 7cc00fbaae..0b0a57c69a 100644 --- a/docs/queryworkers/redis/index.md +++ b/docs/queryworkers/redis/index.md @@ -143,7 +143,8 @@ Response from Redis server: `(integer) 1` :::note -For Redis SET and SORTED SET datatype commands, using same keys for the command will give a syntax error. +For Redis SET and SORTED SET datatype commands, using the same keys for the command gives a syntax error. + ::: :::note From 4a9b3b6a602358d364325cbc01b2de2ae2b676f9 Mon Sep 17 00:00:00 2001 From: Dino Lozina <113168755+dlozina-macrometa@users.noreply.github.com> Date: Fri, 23 Dec 2022 10:07:00 +0100 Subject: [PATCH 07/12] Update docs/queryworkers/redis/redis-sdks.md Co-authored-by: Diana Payton <105658419+diana-macrometa@users.noreply.github.com> --- docs/queryworkers/redis/redis-sdks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/queryworkers/redis/redis-sdks.md b/docs/queryworkers/redis/redis-sdks.md index 9b5f57a16d..d1cf7630fa 100644 --- a/docs/queryworkers/redis/redis-sdks.md +++ b/docs/queryworkers/redis/redis-sdks.md @@ -23,7 +23,7 @@ client = new jsc8({ fabricName: "_system", }); -// We need to create redis collection on platform using SDK, Console or API call +// We need to create a Redis collection on platform using SDK, Console, or API call const REDIS_COLLECTION = "testRedisCollection"; async function redisExample() { From 256748eb39d8365fc54b7723f8da00609e94a823 Mon Sep 17 00:00:00 2001 From: Dino Lozina <113168755+dlozina-macrometa@users.noreply.github.com> Date: Fri, 23 Dec 2022 10:07:07 +0100 Subject: [PATCH 08/12] Update docs/queryworkers/redis/redis-sdks.md Co-authored-by: Diana Payton <105658419+diana-macrometa@users.noreply.github.com> --- docs/queryworkers/redis/redis-sdks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/queryworkers/redis/redis-sdks.md b/docs/queryworkers/redis/redis-sdks.md index d1cf7630fa..bea921863c 100644 --- a/docs/queryworkers/redis/redis-sdks.md +++ b/docs/queryworkers/redis/redis-sdks.md @@ -91,7 +91,7 @@ client = C8Client(protocol='https', host='play.paas.macrometa.io', port=443, apikey="xxxxx", geofabric='_system') -# We need to create redis collection on platform using SDK, Console or API call +# We need to create redis collection on platform using SDK, Console, or API call REDIS_COLLECTION = "test_redis_collection" # String data type example From 9fa448aa3028809df2daf7bbd6f18cc1c8c6e6e2 Mon Sep 17 00:00:00 2001 From: Dino Lozina <113168755+dlozina-macrometa@users.noreply.github.com> Date: Thu, 23 Feb 2023 18:22:40 +0100 Subject: [PATCH 09/12] Update docs/queryworkers/redis/index.md Co-authored-by: James <86624594+jamesm-macrometa@users.noreply.github.com> --- docs/queryworkers/redis/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/queryworkers/redis/index.md b/docs/queryworkers/redis/index.md index 0b0a57c69a..27fa7ccfd8 100644 --- a/docs/queryworkers/redis/index.md +++ b/docs/queryworkers/redis/index.md @@ -145,6 +145,7 @@ Response from Redis server: :::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. ::: :::note From c954c1aad74e04b339e4ff62a256f8675d531242 Mon Sep 17 00:00:00 2001 From: Dino Lozina <113168755+dlozina-macrometa@users.noreply.github.com> Date: Thu, 23 Feb 2023 18:22:50 +0100 Subject: [PATCH 10/12] Update docs/queryworkers/redis/index.md Co-authored-by: James <86624594+jamesm-macrometa@users.noreply.github.com> --- docs/queryworkers/redis/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/queryworkers/redis/index.md b/docs/queryworkers/redis/index.md index 27fa7ccfd8..5af6e0a2cf 100644 --- a/docs/queryworkers/redis/index.md +++ b/docs/queryworkers/redis/index.md @@ -151,4 +151,3 @@ For Redis MSET and HMSET commands, using same keys for the command will give an :::note For Redis MSET and HMSET commands, using same keys for the command will give an invalid command args error. -::: From e966eecfd5e3fbaea2f9357c253afd820fb53b49 Mon Sep 17 00:00:00 2001 From: Dino Lozina <113168755+dlozina-macrometa@users.noreply.github.com> Date: Thu, 23 Feb 2023 18:22:57 +0100 Subject: [PATCH 11/12] Update docs/queryworkers/redis/index.md Co-authored-by: James <86624594+jamesm-macrometa@users.noreply.github.com> --- docs/queryworkers/redis/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/queryworkers/redis/index.md b/docs/queryworkers/redis/index.md index 5af6e0a2cf..8c7c162b51 100644 --- a/docs/queryworkers/redis/index.md +++ b/docs/queryworkers/redis/index.md @@ -149,5 +149,4 @@ For Redis MSET and HMSET commands, using same keys for the command will give an ::: :::note -For Redis MSET and HMSET commands, using same keys for the command will give an invalid command args error. From 242d1783e252a49a372d9a5ef650dc0aebd6cd50 Mon Sep 17 00:00:00 2001 From: Dino Lozina <113168755+dlozina-macrometa@users.noreply.github.com> Date: Thu, 23 Feb 2023 18:23:04 +0100 Subject: [PATCH 12/12] Update docs/queryworkers/redis/index.md Co-authored-by: James <86624594+jamesm-macrometa@users.noreply.github.com> --- docs/queryworkers/redis/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/queryworkers/redis/index.md b/docs/queryworkers/redis/index.md index 8c7c162b51..1ec0500324 100644 --- a/docs/queryworkers/redis/index.md +++ b/docs/queryworkers/redis/index.md @@ -148,5 +148,4 @@ For Redis SET and SORTED SET datatype commands, using the same keys for the comm For Redis MSET and HMSET commands, using same keys for the command will give an invalid command args error. ::: -:::note