From 667ce494ec4f63f196b63fa980bee0557803a433 Mon Sep 17 00:00:00 2001
From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com>
Date: Wed, 11 Sep 2024 15:27:47 +0100
Subject: [PATCH 01/22] DOC-4080 Examples for ZADD and ZRANGE (#332)
* DOC-4080 zadd example
* DOC-4080 added zrange examples
* DOC-4080 dotnet format changes
---
tests/Doc/CmdsSortedSetExamples.cs | 484 +++++++++++++++++++++++++++++
1 file changed, 484 insertions(+)
create mode 100644 tests/Doc/CmdsSortedSetExamples.cs
diff --git a/tests/Doc/CmdsSortedSetExamples.cs b/tests/Doc/CmdsSortedSetExamples.cs
new file mode 100644
index 00000000..6ae81201
--- /dev/null
+++ b/tests/Doc/CmdsSortedSetExamples.cs
@@ -0,0 +1,484 @@
+// EXAMPLE: cmds_sorted_set
+// HIDE_START
+
+using NRedisStack.Tests;
+using StackExchange.Redis;
+
+// HIDE_END
+
+// REMOVE_START
+namespace Doc;
+[Collection("DocsTests")]
+// REMOVE_END
+
+// HIDE_START
+public class CmdsSortedSet
+{
+
+ [SkipIfRedis(Is.OSSCluster)]
+ public void run()
+ {
+ var muxer = ConnectionMultiplexer.Connect("localhost:6379");
+ var db = muxer.GetDatabase();
+ //REMOVE_START
+ // Clear any keys here before using them in tests.
+
+ //REMOVE_END
+ // HIDE_END
+
+
+ // STEP_START bzmpop
+
+ // STEP_END
+
+ // Tests for 'bzmpop' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START bzpopmax
+
+ // STEP_END
+
+ // Tests for 'bzpopmax' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START bzpopmin
+
+ // STEP_END
+
+ // Tests for 'bzpopmin' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zadd
+ bool zAddResult1 = db.SortedSetAdd("myzset", "one", 1);
+ Console.WriteLine(zAddResult1); // >>> True
+
+ bool zAddResult2 = db.SortedSetAdd("myzset", "uno", 1);
+ Console.WriteLine(zAddResult2); // >>> True
+
+ long zAddResult3 = db.SortedSetAdd(
+ "myzset",
+ new SortedSetEntry[] {
+ new SortedSetEntry("two", 2),
+ new SortedSetEntry("three", 3)
+ }
+ );
+ Console.WriteLine(zAddResult3); // >>> 2
+
+ SortedSetEntry[] zAddResult4 = db.SortedSetRangeByRankWithScores("myzset", 0, -1);
+ Console.WriteLine($"{string.Join(", ", zAddResult4.Select(b => $"{b.Element}: {b.Score}"))}");
+ // >>> one: 1, uno: 1, two: 2, three: 3
+ // STEP_END
+
+ // Tests for 'zadd' step.
+ // REMOVE_START
+ Assert.True(zAddResult1);
+ Assert.True(zAddResult2);
+ Assert.Equal(2, zAddResult3);
+ Assert.Equal(
+ "one: 1, uno: 1, two: 2, three: 3",
+ string.Join(", ", zAddResult4.Select(b => $"{b.Element}: {b.Score}"))
+ );
+ db.KeyDelete("myzset");
+ // REMOVE_END
+
+
+ // STEP_START zcard
+
+ // STEP_END
+
+ // Tests for 'zcard' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zcount
+
+ // STEP_END
+
+ // Tests for 'zcount' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zdiff
+
+ // STEP_END
+
+ // Tests for 'zdiff' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zdiffstore
+
+ // STEP_END
+
+ // Tests for 'zdiffstore' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zincrby
+
+ // STEP_END
+
+ // Tests for 'zincrby' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zinter
+
+ // STEP_END
+
+ // Tests for 'zinter' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zintercard
+
+ // STEP_END
+
+ // Tests for 'zintercard' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zinterstore
+
+ // STEP_END
+
+ // Tests for 'zinterstore' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zlexcount
+
+ // STEP_END
+
+ // Tests for 'zlexcount' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zmpop
+
+ // STEP_END
+
+ // Tests for 'zmpop' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zmscore
+
+ // STEP_END
+
+ // Tests for 'zmscore' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zpopmax
+
+ // STEP_END
+
+ // Tests for 'zpopmax' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zpopmin
+
+ // STEP_END
+
+ // Tests for 'zpopmin' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zrandmember
+
+ // STEP_END
+
+ // Tests for 'zrandmember' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zrange1
+ long zRangeResult1 = db.SortedSetAdd(
+ "myzset",
+ new SortedSetEntry[] {
+ new SortedSetEntry("one", 1),
+ new SortedSetEntry("two", 2),
+ new SortedSetEntry("three", 3)
+ }
+ );
+ Console.WriteLine(zRangeResult1); // >>> 3
+
+ RedisValue[] zRangeResult2 = db.SortedSetRangeByRank("myzset", 0, -1);
+ Console.WriteLine(string.Join(", ", zRangeResult2));
+ // >>> one, two, three
+
+ RedisValue[] zRangeResult3 = db.SortedSetRangeByRank("myzset", 2, 3);
+ Console.WriteLine(string.Join(", ", zRangeResult3));
+ // >>> three
+
+ RedisValue[] zRangeResult4 = db.SortedSetRangeByRank("myzset", -2, -1);
+ Console.WriteLine(string.Join(", ", zRangeResult4));
+ // >>> two, three
+ // STEP_END
+
+ // Tests for 'zrange1' step.
+ // REMOVE_START
+ Assert.Equal(3, zRangeResult1);
+ Assert.Equal("one, two, three", string.Join(", ", zRangeResult2));
+ Assert.Equal("three", string.Join(", ", zRangeResult3));
+ Assert.Equal("two, three", string.Join(", ", zRangeResult4));
+ db.KeyDelete("myzset");
+ // REMOVE_END
+
+
+ // STEP_START zrange2
+ long zRangeResult5 = db.SortedSetAdd(
+ "myzset",
+ new SortedSetEntry[] {
+ new SortedSetEntry("one", 1),
+ new SortedSetEntry("two", 2),
+ new SortedSetEntry("three", 3)
+ }
+ );
+
+ SortedSetEntry[] zRangeResult6 = db.SortedSetRangeByRankWithScores("myzset", 0, 1);
+ Console.WriteLine($"{string.Join(", ", zRangeResult6.Select(b => $"{b.Element}: {b.Score}"))}");
+ // >>> one: 1, two: 2
+ // STEP_END
+
+ // Tests for 'zrange2' step.
+ // REMOVE_START
+ Assert.Equal(3, zRangeResult5);
+ Assert.Equal("one: 1, two: 2", string.Join(", ", zRangeResult6.Select(b => $"{b.Element}: {b.Score}")));
+ db.KeyDelete("myzset");
+ // REMOVE_END
+
+
+ // STEP_START zrange3
+ long zRangeResult7 = db.SortedSetAdd(
+ "myzset",
+ new SortedSetEntry[] {
+ new SortedSetEntry("one", 1),
+ new SortedSetEntry("two", 2),
+ new SortedSetEntry("three", 3)
+ }
+ );
+
+ RedisValue[] zRangeResult8 = db.SortedSetRangeByScore(
+ "myzset",
+ 1,
+ double.PositiveInfinity,
+ Exclude.Start,
+ skip: 1, take: 1
+ );
+ Console.WriteLine(string.Join(", ", zRangeResult8));
+ // >>> three
+ // STEP_END
+
+ // Tests for 'zrange3' step.
+ // REMOVE_START
+ Assert.Equal(3, zRangeResult7);
+ Assert.Equal("three", string.Join(", ", zRangeResult8));
+ db.KeyDelete("myzset");
+ // REMOVE_END
+
+
+ // STEP_START zrangebylex
+
+ // STEP_END
+
+ // Tests for 'zrangebylex' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zrangebyscore
+
+ // STEP_END
+
+ // Tests for 'zrangebyscore' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zrangestore
+
+ // STEP_END
+
+ // Tests for 'zrangestore' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zrank
+
+ // STEP_END
+
+ // Tests for 'zrank' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zrem
+
+ // STEP_END
+
+ // Tests for 'zrem' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zremrangebylex
+
+ // STEP_END
+
+ // Tests for 'zremrangebylex' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zremrangebyrank
+
+ // STEP_END
+
+ // Tests for 'zremrangebyrank' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zremrangebyscore
+
+ // STEP_END
+
+ // Tests for 'zremrangebyscore' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zrevrange
+
+ // STEP_END
+
+ // Tests for 'zrevrange' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zrevrangebylex
+
+ // STEP_END
+
+ // Tests for 'zrevrangebylex' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zrevrangebyscore
+
+ // STEP_END
+
+ // Tests for 'zrevrangebyscore' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zrevrank
+
+ // STEP_END
+
+ // Tests for 'zrevrank' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zscan
+
+ // STEP_END
+
+ // Tests for 'zscan' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zscore
+
+ // STEP_END
+
+ // Tests for 'zscore' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zunion
+
+ // STEP_END
+
+ // Tests for 'zunion' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START zunionstore
+
+ // STEP_END
+
+ // Tests for 'zunionstore' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // HIDE_START
+ }
+}
+// HIDE_END
+
From 44a27a0f2ff5327796d4b4b4c66175794e4a899d Mon Sep 17 00:00:00 2001
From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com>
Date: Wed, 11 Sep 2024 18:18:17 +0100
Subject: [PATCH 02/22] DOC-4117 examples for DEL, EXPIRE, and TTL commands
(#333)
* DOC-4117 added EXPIRE examples
* DOC-4117 added TTL example
* DOC-4117 dotnet format changes
* DOC-4117 try to fix expire tests failing for Stack v6.2.6
* DOC-4117 improved SkipIfRedis attribute
* DOC-4117 dotnet format changes
---
tests/Doc/CmdsGenericExample.cs | 438 ++++++++++++++++++++++++++++++++
1 file changed, 438 insertions(+)
create mode 100644 tests/Doc/CmdsGenericExample.cs
diff --git a/tests/Doc/CmdsGenericExample.cs b/tests/Doc/CmdsGenericExample.cs
new file mode 100644
index 00000000..950805bd
--- /dev/null
+++ b/tests/Doc/CmdsGenericExample.cs
@@ -0,0 +1,438 @@
+// EXAMPLE: cmds_generic
+// HIDE_START
+
+using NRedisStack.Tests;
+using StackExchange.Redis;
+
+// HIDE_END
+
+// REMOVE_START
+namespace Doc;
+[Collection("DocsTests")]
+// REMOVE_END
+
+// HIDE_START
+public class CmdsGenericExample
+{
+
+ [SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.0.0")]
+ public void run()
+ {
+ var muxer = ConnectionMultiplexer.Connect("localhost:6379");
+ var db = muxer.GetDatabase();
+ //REMOVE_START
+ // Clear any keys here before using them in tests.
+
+ //REMOVE_END
+ // HIDE_END
+
+
+ // STEP_START copy
+
+ // STEP_END
+
+ // Tests for 'copy' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START del
+ bool delResult1 = db.StringSet("key1", "Hello");
+ Console.WriteLine(delResult1); // >>> true
+
+ bool delResult2 = db.StringSet("key2", "World");
+ Console.WriteLine(delResult2); // >>> true
+
+ long delResult3 = db.KeyDelete(new RedisKey[] { "key1", "key2", "key3" });
+ Console.WriteLine(delResult3); // >>> 2
+ // STEP_END
+
+ // Tests for 'del' step.
+ // REMOVE_START
+ Assert.True(delResult1);
+ Assert.True(delResult2);
+ Assert.Equal(2, delResult3);
+ // REMOVE_END
+
+
+ // STEP_START dump
+
+ // STEP_END
+
+ // Tests for 'dump' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START exists
+
+ // STEP_END
+
+ // Tests for 'exists' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+ // REMOVE_START
+
+ // REMOVE_END
+ // STEP_START expire
+ bool expireResult1 = db.StringSet("mykey", "Hello");
+ Console.WriteLine(expireResult1); // >>> true
+
+ bool expireResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10));
+ Console.WriteLine(expireResult2); // >>> true
+
+ TimeSpan expireResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
+ Console.WriteLine(Math.Round(expireResult3.TotalSeconds)); // >>> 10
+
+ bool expireResult4 = db.StringSet("mykey", "Hello World");
+ Console.WriteLine(expireResult4); // >>> true
+
+ TimeSpan expireResult5 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
+ Console.WriteLine(Math.Round(expireResult5.TotalSeconds).ToString()); // >>> 0
+
+ bool expireResult6 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasExpiry);
+ Console.WriteLine(expireResult6); // >>> false
+
+ TimeSpan expireResult7 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
+ Console.WriteLine(Math.Round(expireResult7.TotalSeconds)); // >>> 0
+
+ bool expireResult8 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasNoExpiry);
+ Console.WriteLine(expireResult8); // >>> true
+
+ TimeSpan expireResult9 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
+ Console.WriteLine(Math.Round(expireResult9.TotalSeconds)); // >>> 10
+ // STEP_END
+
+ // Tests for 'expire' step.
+ // REMOVE_START
+ Assert.True(expireResult1);
+ Assert.True(expireResult2);
+ Assert.Equal(10, Math.Round(expireResult3.TotalSeconds));
+ Assert.True(expireResult4);
+ Assert.Equal(0, Math.Round(expireResult5.TotalSeconds));
+ Assert.False(expireResult6);
+ Assert.Equal(0, Math.Round(expireResult7.TotalSeconds));
+ Assert.True(expireResult8);
+ Assert.Equal(10, Math.Round(expireResult9.TotalSeconds));
+ db.KeyDelete("mykey");
+
+ // REMOVE_END
+
+
+ // STEP_START expireat
+
+ // STEP_END
+
+ // Tests for 'expireat' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START expiretime
+
+ // STEP_END
+
+ // Tests for 'expiretime' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START keys
+
+ // STEP_END
+
+ // Tests for 'keys' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START migrate
+
+ // STEP_END
+
+ // Tests for 'migrate' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START move
+
+ // STEP_END
+
+ // Tests for 'move' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START object_encoding
+
+ // STEP_END
+
+ // Tests for 'object_encoding' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START object_freq
+
+ // STEP_END
+
+ // Tests for 'object_freq' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START object_idletime
+
+ // STEP_END
+
+ // Tests for 'object_idletime' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START object_refcount
+
+ // STEP_END
+
+ // Tests for 'object_refcount' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START persist
+
+ // STEP_END
+
+ // Tests for 'persist' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START pexpire
+
+ // STEP_END
+
+ // Tests for 'pexpire' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START pexpireat
+
+ // STEP_END
+
+ // Tests for 'pexpireat' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START pexpiretime
+
+ // STEP_END
+
+ // Tests for 'pexpiretime' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START pttl
+
+ // STEP_END
+
+ // Tests for 'pttl' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START randomkey
+
+ // STEP_END
+
+ // Tests for 'randomkey' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START rename
+
+ // STEP_END
+
+ // Tests for 'rename' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START renamenx
+
+ // STEP_END
+
+ // Tests for 'renamenx' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START restore
+
+ // STEP_END
+
+ // Tests for 'restore' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START scan1
+
+ // STEP_END
+
+ // Tests for 'scan1' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START scan2
+
+ // STEP_END
+
+ // Tests for 'scan2' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START scan3
+
+ // STEP_END
+
+ // Tests for 'scan3' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START scan4
+
+ // STEP_END
+
+ // Tests for 'scan4' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START sort
+
+ // STEP_END
+
+ // Tests for 'sort' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START sort_ro
+
+ // STEP_END
+
+ // Tests for 'sort_ro' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START touch
+
+ // STEP_END
+
+ // Tests for 'touch' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START ttl
+ bool ttlResult1 = db.StringSet("mykey", "Hello");
+ Console.WriteLine(ttlResult1); // >>> true
+
+ bool ttlResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10));
+ Console.WriteLine(ttlResult2);
+
+ TimeSpan ttlResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero;
+ string ttlRes = Math.Round(ttlResult3.TotalSeconds).ToString();
+ Console.WriteLine(Math.Round(ttlResult3.TotalSeconds)); // >>> 10
+ // STEP_END
+
+ // Tests for 'ttl' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START type
+
+ // STEP_END
+
+ // Tests for 'type' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START unlink
+
+ // STEP_END
+
+ // Tests for 'unlink' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START wait
+
+ // STEP_END
+
+ // Tests for 'wait' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START waitaof
+
+ // STEP_END
+
+ // Tests for 'waitaof' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // HIDE_START
+ }
+}
+// HIDE_END
+
From 3f90d205b297fc9c91d037ce2ad18f0849d7eb85 Mon Sep 17 00:00:00 2001
From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com>
Date: Thu, 12 Sep 2024 09:26:44 +0100
Subject: [PATCH 03/22] DOC-4101 added INCR example (#334)
* DOC-4101 added INCR example
* DOC-4101 delete key after test
---
tests/Doc/CmdsStringExample.cs | 324 +++++++++++++++++++++++++++++++++
1 file changed, 324 insertions(+)
create mode 100644 tests/Doc/CmdsStringExample.cs
diff --git a/tests/Doc/CmdsStringExample.cs b/tests/Doc/CmdsStringExample.cs
new file mode 100644
index 00000000..462cacd1
--- /dev/null
+++ b/tests/Doc/CmdsStringExample.cs
@@ -0,0 +1,324 @@
+// EXAMPLE: cmds_string
+// HIDE_START
+
+using NRedisStack.Tests;
+using StackExchange.Redis;
+
+// HIDE_END
+
+// REMOVE_START
+namespace Doc;
+[Collection("DocsTests")]
+// REMOVE_END
+
+// HIDE_START
+public class CmdsStringExample
+{
+
+ [SkipIfRedis(Is.OSSCluster)]
+ public void run()
+ {
+ var muxer = ConnectionMultiplexer.Connect("localhost:6379");
+ var db = muxer.GetDatabase();
+ //REMOVE_START
+ // Clear any keys here before using them in tests.
+
+ //REMOVE_END
+ // HIDE_END
+
+
+ // STEP_START append1
+
+ // STEP_END
+
+ // Tests for 'append1' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START append2
+
+ // STEP_END
+
+ // Tests for 'append2' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START decr
+
+ // STEP_END
+
+ // Tests for 'decr' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START decrby
+
+ // STEP_END
+
+ // Tests for 'decrby' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START get
+
+ // STEP_END
+
+ // Tests for 'get' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START getdel
+
+ // STEP_END
+
+ // Tests for 'getdel' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START getex
+
+ // STEP_END
+
+ // Tests for 'getex' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START getrange
+
+ // STEP_END
+
+ // Tests for 'getrange' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START getset
+
+ // STEP_END
+
+ // Tests for 'getset' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START incr
+ bool incrResult1 = db.StringSet("mykey", "10");
+ Console.WriteLine(incrResult1); // >>> true
+
+ long incrResult2 = db.StringIncrement("mykey");
+ Console.WriteLine(incrResult2); // >>> 11
+
+ RedisValue incrResult3 = db.StringGet("mykey");
+ Console.WriteLine(incrResult3); // >>> 11
+ // STEP_END
+
+ // Tests for 'incr' step.
+ // REMOVE_START
+ Assert.True(incrResult1);
+ Assert.Equal(11, incrResult2);
+ Assert.Equal("11", incrResult3);
+ db.KeyDelete("mykey");
+ // REMOVE_END
+
+
+ // STEP_START incrby
+
+ // STEP_END
+
+ // Tests for 'incrby' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START incrbyfloat
+
+ // STEP_END
+
+ // Tests for 'incrbyfloat' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START lcs1
+
+ // STEP_END
+
+ // Tests for 'lcs1' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START lcs2
+
+ // STEP_END
+
+ // Tests for 'lcs2' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START lcs3
+
+ // STEP_END
+
+ // Tests for 'lcs3' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START lcs4
+
+ // STEP_END
+
+ // Tests for 'lcs4' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START lcs5
+
+ // STEP_END
+
+ // Tests for 'lcs5' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START mget
+
+ // STEP_END
+
+ // Tests for 'mget' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START mset
+
+ // STEP_END
+
+ // Tests for 'mset' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START msetnx
+
+ // STEP_END
+
+ // Tests for 'msetnx' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START psetex
+
+ // STEP_END
+
+ // Tests for 'psetex' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START set
+
+ // STEP_END
+
+ // Tests for 'set' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START setex
+
+ // STEP_END
+
+ // Tests for 'setex' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START setnx
+
+ // STEP_END
+
+ // Tests for 'setnx' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START setrange1
+
+ // STEP_END
+
+ // Tests for 'setrange1' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START setrange2
+
+ // STEP_END
+
+ // Tests for 'setrange2' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START strlen
+
+ // STEP_END
+
+ // Tests for 'strlen' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // STEP_START substr
+
+ // STEP_END
+
+ // Tests for 'substr' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // HIDE_START
+ }
+}
+// HIDE_END
+
From b21c054b5bd315554b971062c17ffd6eab40f460 Mon Sep 17 00:00:00 2001
From: atakavci <58048133+atakavci@users.noreply.github.com>
Date: Fri, 13 Sep 2024 11:37:15 +0300
Subject: [PATCH 04/22] Update to SE.Redis 2.8.16 (#335)
* Updata to SE.Redis 2.8.12
* upgrade to 2.8.16
---
src/NRedisStack/NRedisStack.csproj | 2 +-
tests/Doc/Doc.csproj | 2 +-
tests/NRedisStack.Tests/NRedisStack.Tests.csproj | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/NRedisStack/NRedisStack.csproj b/src/NRedisStack/NRedisStack.csproj
index f3626ca6..26ddd3b9 100644
--- a/src/NRedisStack/NRedisStack.csproj
+++ b/src/NRedisStack/NRedisStack.csproj
@@ -18,7 +18,7 @@
-
+
diff --git a/tests/Doc/Doc.csproj b/tests/Doc/Doc.csproj
index dec76f61..fefcd82a 100644
--- a/tests/Doc/Doc.csproj
+++ b/tests/Doc/Doc.csproj
@@ -20,7 +20,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/NRedisStack.Tests/NRedisStack.Tests.csproj b/tests/NRedisStack.Tests/NRedisStack.Tests.csproj
index daba5299..7aceede5 100644
--- a/tests/NRedisStack.Tests/NRedisStack.Tests.csproj
+++ b/tests/NRedisStack.Tests/NRedisStack.Tests.csproj
@@ -27,7 +27,7 @@
-
+
From 7aedb1c63bae19485e122849514db3398308ee80 Mon Sep 17 00:00:00 2001
From: atakavci <58048133+atakavci@users.noreply.github.com>
Date: Fri, 13 Sep 2024 16:11:47 +0300
Subject: [PATCH 05/22] Update version to 0.13.0 (#336)
---
src/NRedisStack/NRedisStack.csproj | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/NRedisStack/NRedisStack.csproj b/src/NRedisStack/NRedisStack.csproj
index 26ddd3b9..999af7f1 100644
--- a/src/NRedisStack/NRedisStack.csproj
+++ b/src/NRedisStack/NRedisStack.csproj
@@ -10,9 +10,9 @@
Redis OSS
.Net Client for Redis Stack
README.md
- 0.12.0
- 0.12.0
- 0.12.0
+ 0.13.0
+ 0.13.0
+ 0.13.0
From e7565683dccac6159e227fb0c9cb44845be1b522 Mon Sep 17 00:00:00 2001
From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com>
Date: Thu, 26 Sep 2024 08:24:14 +0100
Subject: [PATCH 06/22] DOC-4251 full text search examples (#339)
---
tests/Doc/QueryFtExample.cs | 274 ++++++++++++++++++++++++++++++++++++
1 file changed, 274 insertions(+)
create mode 100644 tests/Doc/QueryFtExample.cs
diff --git a/tests/Doc/QueryFtExample.cs b/tests/Doc/QueryFtExample.cs
new file mode 100644
index 00000000..bc7f544b
--- /dev/null
+++ b/tests/Doc/QueryFtExample.cs
@@ -0,0 +1,274 @@
+// EXAMPLE: query_ft
+// HIDE_START
+
+using NRedisStack.RedisStackCommands;
+using NRedisStack.Search;
+using NRedisStack.Search.Literals.Enums;
+using NRedisStack.Tests;
+using StackExchange.Redis;
+
+// HIDE_END
+
+// REMOVE_START
+namespace Doc;
+[Collection("DocsTests")]
+// REMOVE_END
+
+// HIDE_START
+public class QueryFtExample
+{
+
+ [SkipIfRedis(Is.OSSCluster)]
+ public void run()
+ {
+ var muxer = ConnectionMultiplexer.Connect("localhost:6379");
+ var db = muxer.GetDatabase();
+ //REMOVE_START
+ // Clear any keys here before using them in tests.
+ try { db.FT().DropIndex("idx:bicycle", true); } catch { }
+ //REMOVE_END
+
+ Schema bikeSchema = new Schema()
+ .AddTextField(new FieldName("$.brand", "brand"))
+ .AddTextField(new FieldName("$.model", "model"))
+ .AddTextField(new FieldName("$.description", "description"));
+
+ FTCreateParams bikeParams = new FTCreateParams()
+ .AddPrefix("bicycle:")
+ .On(IndexDataType.JSON);
+
+ db.FT().Create("idx:bicycle", bikeParams, bikeSchema);
+
+ var bicycles = new object[]
+ {
+ new
+ {
+ brand = "Velorim",
+ model = "Jigger",
+ price = 270,
+ description = "Small and powerful, the Jigger is the best ride " +
+ "for the smallest of tikes! This is the tiniest " +
+ "kids’ pedal bike on the market available without" +
+ " a coaster brake, the Jigger is the vehicle of " +
+ "choice for the rare tenacious little rider " +
+ "raring to go.",
+ condition = "used"
+ },
+ new
+ {
+ brand = "Bicyk",
+ model = "Hillcraft",
+ price = 1200,
+ description = "Kids want to ride with as little weight as possible." +
+ " Especially on an incline! They may be at the age " +
+ "when a 27.5 inch wheel bike is just too clumsy coming " +
+ "off a 24 inch bike. The Hillcraft 26 is just the solution" +
+ " they need!",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Nord",
+ model = "Chook air 5",
+ price = 815,
+ description = "The Chook Air 5 gives kids aged six years and older " +
+ "a durable and uberlight mountain bike for their first" +
+ " experience on tracks and easy cruising through forests" +
+ " and fields. The lower top tube makes it easy to mount" +
+ " and dismount in any situation, giving your kids greater" +
+ " safety on the trails.",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Eva",
+ model = "Eva 291",
+ price = 3400,
+ description = "The sister company to Nord, Eva launched in 2005 as the" +
+ " first and only women-dedicated bicycle brand. Designed" +
+ " by women for women, allEva bikes are optimized for the" +
+ " feminine physique using analytics from a body metrics" +
+ " database. If you like 29ers, try the Eva 291. It’s a " +
+ "brand new bike for 2022.. This full-suspension, " +
+ "cross-country ride has been designed for velocity. The" +
+ " 291 has 100mm of front and rear travel, a superlight " +
+ "aluminum frame and fast-rolling 29-inch wheels. Yippee!",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Noka Bikes",
+ model = "Kahuna",
+ price = 3200,
+ description = "Whether you want to try your hand at XC racing or are " +
+ "looking for a lively trail bike that's just as inspiring" +
+ " on the climbs as it is over rougher ground, the Wilder" +
+ " is one heck of a bike built specifically for short women." +
+ " Both the frames and components have been tweaked to " +
+ "include a women’s saddle, different bars and unique " +
+ "colourway.",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Breakout",
+ model = "XBN 2.1 Alloy",
+ price = 810,
+ description = "The XBN 2.1 Alloy is our entry-level road bike – but that’s" +
+ " not to say that it’s a basic machine. With an internal " +
+ "weld aluminium frame, a full carbon fork, and the slick-shifting" +
+ " Claris gears from Shimano’s, this is a bike which doesn’t" +
+ " break the bank and delivers craved performance.",
+ condition = "new",
+ },
+ new
+ {
+ brand = "ScramBikes",
+ model = "WattBike",
+ price = 2300,
+ description = "The WattBike is the best e-bike for people who still feel young" +
+ " at heart. It has a Bafang 1000W mid-drive system and a 48V" +
+ " 17.5AH Samsung Lithium-Ion battery, allowing you to ride for" +
+ " more than 60 miles on one charge. It’s great for tackling hilly" +
+ " terrain or if you just fancy a more leisurely ride. With three" +
+ " working modes, you can choose between E-bike, assisted bicycle," +
+ " and normal bike modes.",
+ condition = "new",
+ },
+ new
+ {
+ brand = "Peaknetic",
+ model = "Secto",
+ price = 430,
+ description = "If you struggle with stiff fingers or a kinked neck or back after" +
+ " a few minutes on the road, this lightweight, aluminum bike" +
+ " alleviates those issues and allows you to enjoy the ride. From" +
+ " the ergonomic grips to the lumbar-supporting seat position, the" +
+ " Roll Low-Entry offers incredible comfort. The rear-inclined seat" +
+ " tube facilitates stability by allowing you to put a foot on the" +
+ " ground to balance at a stop, and the low step-over frame makes it" +
+ " accessible for all ability and mobility levels. The saddle is" +
+ " very soft, with a wide back to support your hip joints and a" +
+ " cutout in the center to redistribute that pressure. Rim brakes" +
+ " deliver satisfactory braking control, and the wide tires provide" +
+ " a smooth, stable ride on paved roads and gravel. Rack and fender" +
+ " mounts facilitate setting up the Roll Low-Entry as your preferred" +
+ " commuter, and the BMX-like handlebar offers space for mounting a" +
+ " flashlight, bell, or phone holder.",
+ condition = "new",
+ },
+ new
+ {
+ brand = "nHill",
+ model = "Summit",
+ price = 1200,
+ description = "This budget mountain bike from nHill performs well both on bike" +
+ " paths and on the trail. The fork with 100mm of travel absorbs" +
+ " rough terrain. Fat Kenda Booster tires give you grip in corners" +
+ " and on wet trails. The Shimano Tourney drivetrain offered enough" +
+ " gears for finding a comfortable pace to ride uphill, and the" +
+ " Tektro hydraulic disc brakes break smoothly. Whether you want an" +
+ " affordable bike that you can take to work, but also take trail in" +
+ " mountains on the weekends or you’re just after a stable," +
+ " comfortable ride for the bike path, the Summit gives a good value" +
+ " for money.",
+ condition = "new",
+ },
+ new
+ {
+ model = "ThrillCycle",
+ brand = "BikeShind",
+ price = 815,
+ description = "An artsy, retro-inspired bicycle that’s as functional as it is" +
+ " pretty: The ThrillCycle steel frame offers a smooth ride. A" +
+ " 9-speed drivetrain has enough gears for coasting in the city, but" +
+ " we wouldn’t suggest taking it to the mountains. Fenders protect" +
+ " you from mud, and a rear basket lets you transport groceries," +
+ " flowers and books. The ThrillCycle comes with a limited lifetime" +
+ " warranty, so this little guy will last you long past graduation.",
+ condition = "refurbished",
+ },
+ };
+
+ for (var i = 0; i < bicycles.Length; i++)
+ {
+ db.JSON().Set($"bicycle:{i}", "$", bicycles[i]);
+ }
+ // HIDE_END
+
+
+ // STEP_START ft1
+ SearchResult res1 = db.FT().Search(
+ "idx:bicycle",
+ new Query("@description: kids")
+ );
+ Console.WriteLine(res1); // >>> 2
+ // STEP_END
+
+ // Tests for 'ft1' step.
+ // REMOVE_START
+ Assert.Equal(2, res1.TotalResults);
+ // REMOVE_END
+
+
+ // STEP_START ft2
+ SearchResult res2 = db.FT().Search(
+ "idx:bicycle",
+ new Query("@model: ka*")
+ );
+ Console.WriteLine(res2.TotalResults); // >>> 1
+ // STEP_END
+
+ // Tests for 'ft2' step.
+ // REMOVE_START
+ Assert.Equal(1, res2.TotalResults);
+ // REMOVE_END
+
+
+ // STEP_START ft3
+ SearchResult res3 = db.FT().Search(
+ "idx:bicycle",
+ new Query("@brand: *bikes")
+ );
+ Console.WriteLine(res3.TotalResults); // >>> 2
+ // STEP_END
+
+ // Tests for 'ft3' step.
+ // REMOVE_START
+ Assert.Equal(2, res3.TotalResults);
+ // REMOVE_END
+
+
+ // STEP_START ft4
+ SearchResult res4 = db.FT().Search(
+ "idx:bicycle",
+ new Query("%optamized%")
+ );
+ Console.WriteLine(res4.TotalResults); // >>> 1
+ // STEP_END
+
+ // Tests for 'ft4' step.
+ // REMOVE_START
+ Assert.Equal(1, res4.TotalResults);
+ // REMOVE_END
+
+
+ // STEP_START ft5
+ SearchResult res5 = db.FT().Search(
+ "idx:bicycle",
+ new Query("%%optamised%%")
+ );
+ Console.WriteLine(res5.TotalResults); // >>> 1
+ // STEP_END
+
+ // Tests for 'ft5' step.
+ // REMOVE_START
+ Assert.Equal(1, res5.TotalResults);
+ // REMOVE_END
+
+
+ // HIDE_START
+ }
+}
+// HIDE_END
+
From cb6d6850304bce0c315696ed42162e9da8bf3413 Mon Sep 17 00:00:00 2001
From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com>
Date: Fri, 27 Sep 2024 14:21:23 +0100
Subject: [PATCH 07/22] DOC-4243 added range query examples (#338)
* DOC-4243 added range query examples
* DOC-4243 implemented PR feedback
* DOC-4243 reinstated filter example using infinity
---
tests/Doc/QueryRangeExample.cs | 273 +++++++++++++++++++++++++++++++++
1 file changed, 273 insertions(+)
create mode 100644 tests/Doc/QueryRangeExample.cs
diff --git a/tests/Doc/QueryRangeExample.cs b/tests/Doc/QueryRangeExample.cs
new file mode 100644
index 00000000..44755930
--- /dev/null
+++ b/tests/Doc/QueryRangeExample.cs
@@ -0,0 +1,273 @@
+// EXAMPLE: query_range
+// HIDE_START
+
+using NRedisStack.RedisStackCommands;
+using NRedisStack.Search;
+using NRedisStack.Search.Literals.Enums;
+using NRedisStack.Tests;
+using StackExchange.Redis;
+
+// HIDE_END
+
+// REMOVE_START
+namespace Doc;
+[Collection("DocsTests")]
+// REMOVE_END
+
+// HIDE_START
+public class QueryRangeExample
+{
+
+ [SkipIfRedis(Is.OSSCluster)]
+ public void run()
+ {
+ var muxer = ConnectionMultiplexer.Connect("localhost:6379");
+ var db = muxer.GetDatabase();
+ //REMOVE_START
+ // Clear any keys here before using them in tests.
+ try { db.FT().DropIndex("idx:bicycle", dd: true); } catch { }
+ //REMOVE_END
+
+ Schema bikeSchema = new Schema()
+ .AddTextField(new FieldName("$.description", "description"))
+ .AddNumericField(new FieldName("$.price", "price"))
+ .AddTagField(new FieldName("$.condition", "condition"));
+
+ FTCreateParams bikeParams = new FTCreateParams()
+ .AddPrefix("bicycle:")
+ .On(IndexDataType.JSON);
+
+ db.FT().Create("idx:bicycle", bikeParams, bikeSchema);
+
+ var bicycles = new object[]
+ {
+ new
+ {
+ brand = "Velorim",
+ model = "Jigger",
+ price = 270,
+ description = "Small and powerful, the Jigger is the best ride " +
+ "for the smallest of tikes! This is the tiniest " +
+ "kids’ pedal bike on the market available without" +
+ " a coaster brake, the Jigger is the vehicle of " +
+ "choice for the rare tenacious little rider " +
+ "raring to go.",
+ condition = "used"
+ },
+ new
+ {
+ brand = "Bicyk",
+ model = "Hillcraft",
+ price = 1200,
+ description = "Kids want to ride with as little weight as possible." +
+ " Especially on an incline! They may be at the age " +
+ "when a 27.5 inch wheel bike is just too clumsy coming " +
+ "off a 24 inch bike. The Hillcraft 26 is just the solution" +
+ " they need!",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Nord",
+ model = "Chook air 5",
+ price = 815,
+ description = "The Chook Air 5 gives kids aged six years and older " +
+ "a durable and uberlight mountain bike for their first" +
+ " experience on tracks and easy cruising through forests" +
+ " and fields. The lower top tube makes it easy to mount" +
+ " and dismount in any situation, giving your kids greater" +
+ " safety on the trails.",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Eva",
+ model = "Eva 291",
+ price = 3400,
+ description = "The sister company to Nord, Eva launched in 2005 as the" +
+ " first and only women-dedicated bicycle brand. Designed" +
+ " by women for women, allEva bikes are optimized for the" +
+ " feminine physique using analytics from a body metrics" +
+ " database. If you like 29ers, try the Eva 291. It’s a " +
+ "brand new bike for 2022.. This full-suspension, " +
+ "cross-country ride has been designed for velocity. The" +
+ " 291 has 100mm of front and rear travel, a superlight " +
+ "aluminum frame and fast-rolling 29-inch wheels. Yippee!",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Noka Bikes",
+ model = "Kahuna",
+ price = 3200,
+ description = "Whether you want to try your hand at XC racing or are " +
+ "looking for a lively trail bike that's just as inspiring" +
+ " on the climbs as it is over rougher ground, the Wilder" +
+ " is one heck of a bike built specifically for short women." +
+ " Both the frames and components have been tweaked to " +
+ "include a women’s saddle, different bars and unique " +
+ "colourway.",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Breakout",
+ model = "XBN 2.1 Alloy",
+ price = 810,
+ description = "The XBN 2.1 Alloy is our entry-level road bike – but that’s" +
+ " not to say that it’s a basic machine. With an internal " +
+ "weld aluminium frame, a full carbon fork, and the slick-shifting" +
+ " Claris gears from Shimano’s, this is a bike which doesn’t" +
+ " break the bank and delivers craved performance.",
+ condition = "new",
+ },
+ new
+ {
+ brand = "ScramBikes",
+ model = "WattBike",
+ price = 2300,
+ description = "The WattBike is the best e-bike for people who still feel young" +
+ " at heart. It has a Bafang 1000W mid-drive system and a 48V" +
+ " 17.5AH Samsung Lithium-Ion battery, allowing you to ride for" +
+ " more than 60 miles on one charge. It’s great for tackling hilly" +
+ " terrain or if you just fancy a more leisurely ride. With three" +
+ " working modes, you can choose between E-bike, assisted bicycle," +
+ " and normal bike modes.",
+ condition = "new",
+ },
+ new
+ {
+ brand = "Peaknetic",
+ model = "Secto",
+ price = 430,
+ description = "If you struggle with stiff fingers or a kinked neck or back after" +
+ " a few minutes on the road, this lightweight, aluminum bike" +
+ " alleviates those issues and allows you to enjoy the ride. From" +
+ " the ergonomic grips to the lumbar-supporting seat position, the" +
+ " Roll Low-Entry offers incredible comfort. The rear-inclined seat" +
+ " tube facilitates stability by allowing you to put a foot on the" +
+ " ground to balance at a stop, and the low step-over frame makes it" +
+ " accessible for all ability and mobility levels. The saddle is" +
+ " very soft, with a wide back to support your hip joints and a" +
+ " cutout in the center to redistribute that pressure. Rim brakes" +
+ " deliver satisfactory braking control, and the wide tires provide" +
+ " a smooth, stable ride on paved roads and gravel. Rack and fender" +
+ " mounts facilitate setting up the Roll Low-Entry as your preferred" +
+ " commuter, and the BMX-like handlebar offers space for mounting a" +
+ " flashlight, bell, or phone holder.",
+ condition = "new",
+ },
+ new
+ {
+ brand = "nHill",
+ model = "Summit",
+ price = 1200,
+ description = "This budget mountain bike from nHill performs well both on bike" +
+ " paths and on the trail. The fork with 100mm of travel absorbs" +
+ " rough terrain. Fat Kenda Booster tires give you grip in corners" +
+ " and on wet trails. The Shimano Tourney drivetrain offered enough" +
+ " gears for finding a comfortable pace to ride uphill, and the" +
+ " Tektro hydraulic disc brakes break smoothly. Whether you want an" +
+ " affordable bike that you can take to work, but also take trail in" +
+ " mountains on the weekends or you’re just after a stable," +
+ " comfortable ride for the bike path, the Summit gives a good value" +
+ " for money.",
+ condition = "new",
+ },
+ new
+ {
+ model = "ThrillCycle",
+ brand = "BikeShind",
+ price = 815,
+ description = "An artsy, retro-inspired bicycle that’s as functional as it is" +
+ " pretty: The ThrillCycle steel frame offers a smooth ride. A" +
+ " 9-speed drivetrain has enough gears for coasting in the city, but" +
+ " we wouldn’t suggest taking it to the mountains. Fenders protect" +
+ " you from mud, and a rear basket lets you transport groceries," +
+ " flowers and books. The ThrillCycle comes with a limited lifetime" +
+ " warranty, so this little guy will last you long past graduation.",
+ condition = "refurbished",
+ },
+ };
+
+ for (var i = 0; i < bicycles.Length; i++)
+ {
+ db.JSON().Set($"bicycle:{i}", "$", bicycles[i]);
+ }
+ // HIDE_END
+
+
+ // STEP_START range1
+ SearchResult res1 = db.FT().Search(
+ "idx:bicycle",
+ new Query("@price:[500 1000]")
+ );
+ Console.WriteLine(res1.TotalResults); // >>> 3
+ // STEP_END
+
+ // Tests for 'range1' step.
+ // REMOVE_START
+ Assert.Equal(3, res1.TotalResults);
+ // REMOVE_END
+
+
+ // STEP_START range2
+ SearchResult res2 = db.FT().Search(
+ "idx:bicycle",
+ new Query().AddFilter(
+ new Query.NumericFilter("price", 500, 1000)
+ )
+ );
+ Console.WriteLine(res2.TotalResults); // >>> 3
+ // STEP_END
+
+ // Tests for 'range2' step.
+ // REMOVE_START
+ Assert.Equal(3, res2.TotalResults);
+ // REMOVE_END
+
+
+ // STEP_START range3
+ SearchResult res3 = db.FT().Search(
+ "idx:bicycle",
+ new Query("*").AddFilter(new Query.NumericFilter(
+ "price", 1000, true, Double.PositiveInfinity, false
+ )
+ )
+ );
+ Console.WriteLine(res3.TotalResults); // >>> 5
+ // STEP_END
+
+ // Tests for 'range3' step.
+ // REMOVE_START
+ Assert.Equal(5, res3.TotalResults);
+ // REMOVE_END
+
+
+ // STEP_START range4
+ SearchResult res4 = db.FT().Search(
+ "idx:bicycle",
+ new Query("@price:[-inf 2000]")
+ .SetSortBy("price")
+ .Limit(0, 5)
+ );
+ Console.WriteLine(res4.TotalResults); // >>> 7
+ Console.WriteLine($"Prices: {string.Join(", ", res4.Documents.Select(d => d["price"]))}");
+ // >>> Prices: 270, 430, 810, 815, 815
+ // STEP_END
+
+ // Tests for 'range4' step.
+ // REMOVE_START
+ Assert.Equal(7, res4.TotalResults);
+ Assert.Equal(
+ "Prices: 270, 430, 810, 815, 815",
+ $"Prices: {string.Join(", ", res4.Documents.Select(d => d["price"]))}"
+ );
+ // REMOVE_END
+
+
+ // HIDE_START
+ }
+}
+// HIDE_END
+
From 7f93841015cf6ebc4e39c13d251cbd707383a7ef Mon Sep 17 00:00:00 2001
From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com>
Date: Fri, 27 Sep 2024 23:09:43 +0100
Subject: [PATCH 08/22] DOC-4295 added aggregate query examples (#341)
* DOC-4295 added aggregate query examples
* DOC-4295 added try-catch around dropIndex call
* DOC-4295 fixed non-deterministic tests
* DOC-4295 replaced dodgy agg4 example for examination
* DOC-4295 reinstated missing example message
---
tests/Doc/QueryAggExample.cs | 327 +++++++++++++++++++++++++++++++++++
1 file changed, 327 insertions(+)
create mode 100644 tests/Doc/QueryAggExample.cs
diff --git a/tests/Doc/QueryAggExample.cs b/tests/Doc/QueryAggExample.cs
new file mode 100644
index 00000000..ec5f696d
--- /dev/null
+++ b/tests/Doc/QueryAggExample.cs
@@ -0,0 +1,327 @@
+// EXAMPLE: query_agg
+// HIDE_START
+
+using NRedisStack.RedisStackCommands;
+using NRedisStack.Search;
+using NRedisStack.Search.Aggregation;
+using NRedisStack.Search.Literals.Enums;
+using NRedisStack.Tests;
+using StackExchange.Redis;
+
+// HIDE_END
+
+// REMOVE_START
+namespace Doc;
+[Collection("DocsTests")]
+// REMOVE_END
+
+// HIDE_START
+public class QueryAggExample
+{
+
+ [SkipIfRedis(Is.OSSCluster)]
+ public void run()
+ {
+ var muxer = ConnectionMultiplexer.Connect("localhost:6379");
+ var db = muxer.GetDatabase();
+ //REMOVE_START
+ // Clear any keys here before using them in tests.
+ try { db.FT().DropIndex("idx:bicycle"); } catch { }
+ //REMOVE_END
+
+ Schema bikeSchema = new Schema()
+ .AddTagField(new FieldName("$.condition", "condition"))
+ .AddNumericField(new FieldName("$.price", "price"));
+
+ FTCreateParams bikeParams = new FTCreateParams()
+ .AddPrefix("bicycle:")
+ .On(IndexDataType.JSON);
+
+ db.FT().Create("idx:bicycle", bikeParams, bikeSchema);
+
+ var bicycles = new object[] {
+ new
+ {
+ pickup_zone = "POLYGON((-74.0610 40.7578, -73.9510 40.7578, -73.9510 40.6678, -74.0610 40.6678, -74.0610 40.7578))",
+ store_location = "-74.0060,40.7128",
+ brand = "Velorim",
+ model = "Jigger",
+ price = 270,
+ description = "Small and powerful, the Jigger is the best ride for the smallest of tikes! This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger is the vehicle of choice for the rare tenacious little rider raring to go.",
+ condition = "new"
+ },
+ new
+ {
+ pickup_zone = "POLYGON((-118.2887 34.0972, -118.1987 34.0972, -118.1987 33.9872, -118.2887 33.9872, -118.2887 34.0972))",
+ store_location = "-118.2437,34.0522",
+ brand = "Bicyk",
+ model = "Hillcraft",
+ price = 1200,
+ description = "Kids want to ride with as little weight as possible. Especially on an incline! They may be at the age when a 27.5\" wheel bike is just too clumsy coming off a 24\" bike. The Hillcraft 26 is just the solution they need!",
+ condition = "used"
+ },
+ new
+ {
+ pickup_zone = "POLYGON((-87.6848 41.9331, -87.5748 41.9331, -87.5748 41.8231, -87.6848 41.8231, -87.6848 41.9331))",
+ store_location = "-87.6298,41.8781",
+ brand = "Nord",
+ model = "Chook air 5",
+ price = 815,
+ description = "The Chook Air 5 gives kids aged six years and older a durable and uberlight mountain bike for their first experience on tracks and easy cruising through forests and fields. The lower top tube makes it easy to mount and dismount in any situation, giving your kids greater safety on the trails.",
+ condition = "used"
+ },
+ new
+ {
+ pickup_zone = "POLYGON((-80.2433 25.8067, -80.1333 25.8067, -80.1333 25.6967, -80.2433 25.6967, -80.2433 25.8067))",
+ store_location = "-80.1918,25.7617",
+ brand = "Eva",
+ model = "Eva 291",
+ price = 3400,
+ description = "The sister company to Nord, Eva launched in 2005 as the first and only women-dedicated bicycle brand. Designed by women for women, allEva bikes are optimized for the feminine physique using analytics from a body metrics database. If you like 29ers, try the Eva 291. It’s a brand new bike for 2022.. This full-suspension, cross-country ride has been designed for velocity. The 291 has 100mm of front and rear travel, a superlight aluminum frame and fast-rolling 29-inch wheels. Yippee!",
+ condition = "used"
+ },
+ new
+ {
+ pickup_zone = "POLYGON((-122.4644 37.8199, -122.3544 37.8199, -122.3544 37.7099, -122.4644 37.7099, -122.4644 37.8199))",
+ store_location = "-122.4194,37.7749",
+ brand = "Noka Bikes",
+ model = "Kahuna",
+ price = 3200,
+ description = "Whether you want to try your hand at XC racing or are looking for a lively trail bike that's just as inspiring on the climbs as it is over rougher ground, the Wilder is one heck of a bike built specifically for short women. Both the frames and components have been tweaked to include a women’s saddle, different bars and unique colourway.",
+ condition = "used"
+ },
+ new
+ {
+ pickup_zone = "POLYGON((-0.1778 51.5524, 0.0822 51.5524, 0.0822 51.4024, -0.1778 51.4024, -0.1778 51.5524))",
+ store_location = "-0.1278,51.5074",
+ brand = "Breakout",
+ model = "XBN 2.1 Alloy",
+ price = 810,
+ description = "The XBN 2.1 Alloy is our entry-level road bike – but that’s not to say that it’s a basic machine. With an internal weld aluminium frame, a full carbon fork, and the slick-shifting Claris gears from Shimano’s, this is a bike which doesn’t break the bank and delivers craved performance.",
+ condition = "new"
+ },
+ new
+ {
+ pickup_zone = "POLYGON((2.1767 48.9016, 2.5267 48.9016, 2.5267 48.5516, 2.1767 48.5516, 2.1767 48.9016))",
+ store_location = "2.3522,48.8566",
+ brand = "ScramBikes",
+ model = "WattBike",
+ price = 2300,
+ description = "The WattBike is the best e-bike for people who still feel young at heart. It has a Bafang 1000W mid-drive system and a 48V 17.5AH Samsung Lithium-Ion battery, allowing you to ride for more than 60 miles on one charge. It’s great for tackling hilly terrain or if you just fancy a more leisurely ride. With three working modes, you can choose between E-bike, assisted bicycle, and normal bike modes.",
+ condition = "new"
+ },
+ new
+ {
+ pickup_zone = "POLYGON((13.3260 52.5700, 13.6550 52.5700, 13.6550 52.2700, 13.3260 52.2700, 13.3260 52.5700))",
+ store_location = "13.4050,52.5200",
+ brand = "Peaknetic",
+ model = "Secto",
+ price = 430,
+ description = "If you struggle with stiff fingers or a kinked neck or back after a few minutes on the road, this lightweight, aluminum bike alleviates those issues and allows you to enjoy the ride. From the ergonomic grips to the lumbar-supporting seat position, the Roll Low-Entry offers incredible comfort. The rear-inclined seat tube facilitates stability by allowing you to put a foot on the ground to balance at a stop, and the low step-over frame makes it accessible for all ability and mobility levels. The saddle is very soft, with a wide back to support your hip joints and a cutout in the center to redistribute that pressure. Rim brakes deliver satisfactory braking control, and the wide tires provide a smooth, stable ride on paved roads and gravel. Rack and fender mounts facilitate setting up the Roll Low-Entry as your preferred commuter, and the BMX-like handlebar offers space for mounting a flashlight, bell, or phone holder.",
+ condition = "new"
+ },
+ new
+ {
+ pickup_zone = "POLYGON((1.9450 41.4301, 2.4018 41.4301, 2.4018 41.1987, 1.9450 41.1987, 1.9450 41.4301))",
+ store_location = "2.1734, 41.3851",
+ brand = "nHill",
+ model = "Summit",
+ price = 1200,
+ description = "This budget mountain bike from nHill performs well both on bike paths and on the trail. The fork with 100mm of travel absorbs rough terrain. Fat Kenda Booster tires give you grip in corners and on wet trails. The Shimano Tourney drivetrain offered enough gears for finding a comfortable pace to ride uphill, and the Tektro hydraulic disc brakes break smoothly. Whether you want an affordable bike that you can take to work, but also take trail in mountains on the weekends or you’re just after a stable, comfortable ride for the bike path, the Summit gives a good value for money.",
+ condition = "new"
+ },
+ new
+ {
+ pickup_zone = "POLYGON((12.4464 42.1028, 12.5464 42.1028, 12.5464 41.7028, 12.4464 41.7028, 12.4464 42.1028))",
+ store_location = "12.4964,41.9028",
+ model = "ThrillCycle",
+ brand = "BikeShind",
+ price = 815,
+ description = "An artsy, retro-inspired bicycle that’s as functional as it is pretty: The ThrillCycle steel frame offers a smooth ride. A 9-speed drivetrain has enough gears for coasting in the city, but we wouldn’t suggest taking it to the mountains. Fenders protect you from mud, and a rear basket lets you transport groceries, flowers and books. The ThrillCycle comes with a limited lifetime warranty, so this little guy will last you long past graduation.",
+ condition = "refurbished"
+ }
+ };
+
+ for (var i = 0; i < bicycles.Length; i++)
+ {
+ db.JSON().Set($"bicycle:{i}", "$", bicycles[i]);
+ }
+ // HIDE_END
+
+
+ // STEP_START agg1
+ AggregationResult res1 = db.FT().Aggregate(
+ "idx:bicycle",
+ new AggregationRequest("@condition:{new}")
+ .Load(new FieldName("__key"), new FieldName("price"))
+ .Apply("@price - (@price * 0.1)", "discounted")
+ );
+ Console.WriteLine(res1.TotalResults); // >>> 5
+
+ for (int i = 0; i < res1.TotalResults; i++)
+ {
+ Row res1Row = res1.GetRow(i);
+
+ Console.WriteLine(
+ $"Key: {res1Row["__key"]}, Price: {res1Row["price"]}, Discounted: {res1Row["discounted"]}"
+ );
+ }
+ // >>> Key: bicycle:0, Price: 270, Discounted: 243
+ // >>> Key: bicycle:5, Price: 810, Discounted: 729
+ // >>> Key: bicycle:6, Price: 2300, Discounted: 2070
+ // >>> Key: bicycle:7, Price: 430, Discounted: 387
+ // >>> Key: bicycle:8, Price: 1200, Discounted: 1080
+ // STEP_END
+
+ // Tests for 'agg1' step.
+ // REMOVE_START
+ Assert.Equal(5, res1.TotalResults);
+
+ for (int i = 0; i < 5; i++)
+ {
+ Row test1Row = res1.GetRow(i);
+
+ switch (test1Row["__key"])
+ {
+ case "bicycle:0":
+ Assert.Equal(
+ "Key: bicycle:0, Price: 270, Discounted: 243",
+ $"Key: {test1Row["__key"]}, Price: {test1Row["price"]}, Discounted: {test1Row["discounted"]}"
+ );
+ break;
+
+ case "bicycle:5":
+ Assert.Equal(
+ "Key: bicycle:5, Price: 810, Discounted: 729",
+ $"Key: {test1Row["__key"]}, Price: {test1Row["price"]}, Discounted: {test1Row["discounted"]}"
+ );
+ break;
+
+ case "bicycle:6":
+ Assert.Equal(
+ "Key: bicycle:6, Price: 2300, Discounted: 2070",
+ $"Key: {test1Row["__key"]}, Price: {test1Row["price"]}, Discounted: {test1Row["discounted"]}"
+ );
+ break;
+
+ case "bicycle:7":
+ Assert.Equal(
+ "Key: bicycle:7, Price: 430, Discounted: 387",
+ $"Key: {test1Row["__key"]}, Price: {test1Row["price"]}, Discounted: {test1Row["discounted"]}"
+ );
+ break;
+
+ case "bicycle:8":
+ Assert.Equal(
+ "Key: bicycle:8, Price: 1200, Discounted: 1080",
+ $"Key: {test1Row["__key"]}, Price: {test1Row["price"]}, Discounted: {test1Row["discounted"]}"
+ );
+ break;
+ }
+ }
+
+ // REMOVE_END
+
+
+ // STEP_START agg2
+ AggregationResult res2 = db.FT().Aggregate(
+ "idx:bicycle",
+ new AggregationRequest("*")
+ .Load(new FieldName("price"))
+ .Apply("@price<1000", "price_category")
+ .GroupBy(
+ "@condition",
+ Reducers.Sum("@price_category").As("num_affordable")
+ )
+ );
+ Console.WriteLine(res2.TotalResults); // >>> 3
+
+ for (int i = 0; i < res2.TotalResults; i++)
+ {
+ Row res2Row = res2.GetRow(i);
+
+ Console.WriteLine(
+ $"Condition: {res2Row["condition"]}, Num affordable: {res2Row["num_affordable"]}"
+ );
+ }
+ // >>> Condition: refurbished, Num affordable: 1
+ // >>> Condition: used, Num affordable: 1
+ // >>> Condition: new, Num affordable: 3
+ // STEP_END
+
+ // Tests for 'agg2' step.
+ // REMOVE_START
+ Assert.Equal(3, res2.TotalResults);
+
+ for (int i = 0; i < 3; i++)
+ {
+ Row test2Row = res2.GetRow(i);
+ switch (test2Row["condition"])
+ {
+ case "refurbished":
+ Assert.Equal(
+ "Condition: refurbished, Num affordable: 1",
+ $"Condition: {test2Row["condition"]}, Num affordable: {test2Row["num_affordable"]}"
+ );
+ break;
+
+ case "used":
+ Assert.Equal(
+ "Condition: used, Num affordable: 1",
+ $"Condition: {test2Row["condition"]}, Num affordable: {test2Row["num_affordable"]}"
+ );
+ break;
+
+ case "new":
+ Assert.Equal(
+ "Condition: new, Num affordable: 3",
+ $"Condition: {test2Row["condition"]}, Num affordable: {test2Row["num_affordable"]}"
+ );
+ break;
+ }
+ }
+ // REMOVE_END
+
+
+ // STEP_START agg3
+ AggregationResult res3 = db.FT().Aggregate(
+ "idx:bicycle",
+ new AggregationRequest("*")
+ .Apply("'bicycle'", "type")
+ .GroupBy("@type", Reducers.Count().As("num_total"))
+ );
+ Console.WriteLine(res3.TotalResults); // >>> 1
+
+ Row res3Row = res3.GetRow(0);
+ Console.WriteLine($"Type: {res3Row["type"]}, Num total: {res3Row["num_total"]}");
+ // >>> Type: bicycle, Num total: 10
+ // STEP_END
+
+ // Tests for 'agg3' step.
+ // REMOVE_START
+ Assert.Equal(1, res3.TotalResults);
+
+ Assert.Equal(
+ "Type: bicycle, Num total: 10",
+ $"Type: {res3Row["type"]}, Num total: {res3Row["num_total"]}"
+ );
+ // REMOVE_END
+
+
+ // STEP_START agg4
+
+ // Not supported in NRedisStack.
+
+ // STEP_END
+
+ // Tests for 'agg4' step.
+ // REMOVE_START
+
+ // REMOVE_END
+
+
+ // HIDE_START
+ }
+}
+// HIDE_END
+
From 0a8bdfae97c5a18ca178e00bc387f3981d7c5790 Mon Sep 17 00:00:00 2001
From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com>
Date: Mon, 30 Sep 2024 10:16:31 +0100
Subject: [PATCH 09/22] DOC-4201 added exact match query examples (#337)
* DOC-4201 added exact match query examples
* DOC-4201 dotnet format changes
* DOC-4201 removed unused 'using' statements
* DOC-4201 fixed email tag example
---------
Co-authored-by: atakavci <58048133+atakavci@users.noreply.github.com>
---
tests/Doc/QueryEmExample.cs | 284 ++++++++++++++++++++++++++++++++++++
1 file changed, 284 insertions(+)
create mode 100644 tests/Doc/QueryEmExample.cs
diff --git a/tests/Doc/QueryEmExample.cs b/tests/Doc/QueryEmExample.cs
new file mode 100644
index 00000000..590a212d
--- /dev/null
+++ b/tests/Doc/QueryEmExample.cs
@@ -0,0 +1,284 @@
+// EXAMPLE: query_em
+// HIDE_START
+
+using NRedisStack.RedisStackCommands;
+using NRedisStack.Search;
+using NRedisStack.Search.Literals.Enums;
+using NRedisStack.Tests;
+using StackExchange.Redis;
+
+// HIDE_END
+
+// REMOVE_START
+namespace Doc;
+[Collection("DocsTests")]
+// REMOVE_END
+
+// HIDE_START
+public class QueryEmExample
+{
+
+ [SkipIfRedis(Is.OSSCluster)]
+ public void run()
+ {
+ var muxer = ConnectionMultiplexer.Connect("localhost:6379");
+ var db = muxer.GetDatabase();
+ //REMOVE_START
+ // Clear any keys here before using them in tests.
+ try { db.FT().DropIndex("idx:bicycle"); } catch { }
+ try { db.FT().DropIndex("idx:email"); } catch { }
+ //REMOVE_END
+
+ FTCreateParams idxParams = new FTCreateParams()
+ .AddPrefix("bicycle:")
+ .On(IndexDataType.JSON);
+
+ Schema bikeSchema = new Schema()
+ .AddTextField(new FieldName("$.description", "description"))
+ .AddNumericField(new FieldName("$.price", "price"))
+ .AddTagField(new FieldName("$.condition", "condition"));
+
+ db.FT().Create("idx:bicycle", idxParams, bikeSchema);
+
+
+ var bicycles = new object[]
+ {
+ new
+ {
+ brand = "Velorim",
+ model = "Jigger",
+ price = 270,
+ description = "Small and powerful, the Jigger is the best ride " +
+ "for the smallest of tikes! This is the tiniest " +
+ "kids’ pedal bike on the market available without" +
+ " a coaster brake, the Jigger is the vehicle of " +
+ "choice for the rare tenacious little rider " +
+ "raring to go.",
+ condition = "used"
+ },
+ new
+ {
+ brand = "Bicyk",
+ model = "Hillcraft",
+ price = 1200,
+ description = "Kids want to ride with as little weight as possible." +
+ " Especially on an incline! They may be at the age " +
+ "when a 27.5 inch wheel bike is just too clumsy coming " +
+ "off a 24 inch bike. The Hillcraft 26 is just the solution" +
+ " they need!",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Nord",
+ model = "Chook air 5",
+ price = 815,
+ description = "The Chook Air 5 gives kids aged six years and older " +
+ "a durable and uberlight mountain bike for their first" +
+ " experience on tracks and easy cruising through forests" +
+ " and fields. The lower top tube makes it easy to mount" +
+ " and dismount in any situation, giving your kids greater" +
+ " safety on the trails.",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Eva",
+ model = "Eva 291",
+ price = 3400,
+ description = "The sister company to Nord, Eva launched in 2005 as the" +
+ " first and only women-dedicated bicycle brand. Designed" +
+ " by women for women, allEva bikes are optimized for the" +
+ " feminine physique using analytics from a body metrics" +
+ " database. If you like 29ers, try the Eva 291. It’s a " +
+ "brand new bike for 2022.. This full-suspension, " +
+ "cross-country ride has been designed for velocity. The" +
+ " 291 has 100mm of front and rear travel, a superlight " +
+ "aluminum frame and fast-rolling 29-inch wheels. Yippee!",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Noka Bikes",
+ model = "Kahuna",
+ price = 3200,
+ description = "Whether you want to try your hand at XC racing or are " +
+ "looking for a lively trail bike that's just as inspiring" +
+ " on the climbs as it is over rougher ground, the Wilder" +
+ " is one heck of a bike built specifically for short women." +
+ " Both the frames and components have been tweaked to " +
+ "include a women’s saddle, different bars and unique " +
+ "colourway.",
+ condition = "used",
+ },
+ new
+ {
+ brand = "Breakout",
+ model = "XBN 2.1 Alloy",
+ price = 810,
+ description = "The XBN 2.1 Alloy is our entry-level road bike – but that’s" +
+ " not to say that it’s a basic machine. With an internal " +
+ "weld aluminium frame, a full carbon fork, and the slick-shifting" +
+ " Claris gears from Shimano’s, this is a bike which doesn’t" +
+ " break the bank and delivers craved performance.",
+ condition = "new",
+ },
+ new
+ {
+ brand = "ScramBikes",
+ model = "WattBike",
+ price = 2300,
+ description = "The WattBike is the best e-bike for people who still feel young" +
+ " at heart. It has a Bafang 1000W mid-drive system and a 48V" +
+ " 17.5AH Samsung Lithium-Ion battery, allowing you to ride for" +
+ " more than 60 miles on one charge. It’s great for tackling hilly" +
+ " terrain or if you just fancy a more leisurely ride. With three" +
+ " working modes, you can choose between E-bike, assisted bicycle," +
+ " and normal bike modes.",
+ condition = "new",
+ },
+ new
+ {
+ brand = "Peaknetic",
+ model = "Secto",
+ price = 430,
+ description = "If you struggle with stiff fingers or a kinked neck or back after" +
+ " a few minutes on the road, this lightweight, aluminum bike" +
+ " alleviates those issues and allows you to enjoy the ride. From" +
+ " the ergonomic grips to the lumbar-supporting seat position, the" +
+ " Roll Low-Entry offers incredible comfort. The rear-inclined seat" +
+ " tube facilitates stability by allowing you to put a foot on the" +
+ " ground to balance at a stop, and the low step-over frame makes it" +
+ " accessible for all ability and mobility levels. The saddle is" +
+ " very soft, with a wide back to support your hip joints and a" +
+ " cutout in the center to redistribute that pressure. Rim brakes" +
+ " deliver satisfactory braking control, and the wide tires provide" +
+ " a smooth, stable ride on paved roads and gravel. Rack and fender" +
+ " mounts facilitate setting up the Roll Low-Entry as your preferred" +
+ " commuter, and the BMX-like handlebar offers space for mounting a" +
+ " flashlight, bell, or phone holder.",
+ condition = "new",
+ },
+ new
+ {
+ brand = "nHill",
+ model = "Summit",
+ price = 1200,
+ description = "This budget mountain bike from nHill performs well both on bike" +
+ " paths and on the trail. The fork with 100mm of travel absorbs" +
+ " rough terrain. Fat Kenda Booster tires give you grip in corners" +
+ " and on wet trails. The Shimano Tourney drivetrain offered enough" +
+ " gears for finding a comfortable pace to ride uphill, and the" +
+ " Tektro hydraulic disc brakes break smoothly. Whether you want an" +
+ " affordable bike that you can take to work, but also take trail in" +
+ " mountains on the weekends or you’re just after a stable," +
+ " comfortable ride for the bike path, the Summit gives a good value" +
+ " for money.",
+ condition = "new",
+ },
+ new
+ {
+ model = "ThrillCycle",
+ brand = "BikeShind",
+ price = 815,
+ description = "An artsy, retro-inspired bicycle that’s as functional as it is" +
+ " pretty: The ThrillCycle steel frame offers a smooth ride. A" +
+ " 9-speed drivetrain has enough gears for coasting in the city, but" +
+ " we wouldn’t suggest taking it to the mountains. Fenders protect" +
+ " you from mud, and a rear basket lets you transport groceries," +
+ " flowers and books. The ThrillCycle comes with a limited lifetime" +
+ " warranty, so this little guy will last you long past graduation.",
+ condition = "refurbished",
+ },
+ };
+
+ for (var i = 0; i < bicycles.Length; i++)
+ {
+ db.JSON().Set($"bicycle:{i}", "$", bicycles[i]);
+ }
+ // HIDE_END
+
+
+ // STEP_START em1
+ SearchResult res1 = db.FT().Search(
+ "idx:bicycle",
+ new Query("@price:[270 270]")
+ );
+ Console.WriteLine(res1.TotalResults); // >>> 1
+
+ SearchResult res2 = db.FT().Search(
+ "idx:bicycle",
+ new Query().AddFilter(
+ new Query.NumericFilter("price", 270, 270)
+ )
+ );
+ Console.WriteLine(res2.TotalResults); // >>> 1
+ // STEP_END
+
+ // Tests for 'em1' step.
+ // REMOVE_START
+ Assert.Equal(1, res1.TotalResults);
+ Assert.Equal(1, res2.TotalResults);
+ // REMOVE_END
+
+
+ // STEP_START em2
+ SearchResult res3 = db.FT().Search(
+ "idx:bicycle",
+ new Query("@condition:{new}")
+ );
+ Console.WriteLine(res3.TotalResults); // >>> 4
+ // STEP_END
+
+ // Tests for 'em2' step.
+ // REMOVE_START
+ Assert.Equal(4, res3.TotalResults);
+ // REMOVE_END
+
+
+ // STEP_START em3
+ Schema emailSchema = new Schema()
+ .AddTagField(new FieldName("$.email", "email"));
+
+ FTCreateParams emailParams = new FTCreateParams()
+ .AddPrefix("key:")
+ .On(IndexDataType.JSON);
+
+ db.FT().Create("idx:email", emailParams, emailSchema);
+
+ db.JSON().Set("key:1", "$", "{\"email\": \"test@redis.com\"}");
+
+
+ SearchResult res4 = db.FT().Search(
+ "idx:email",
+ new Query("@email:{test\\@redis\\.com}").Dialect(2)
+ );
+ Console.WriteLine(res4.TotalResults); // >>> 1
+ // STEP_END
+
+ // Tests for 'em3' step.
+ // REMOVE_START
+ db.FT().DropIndex("idx:email");
+ Assert.Equal(1, res4.TotalResults);
+ // REMOVE_END
+
+
+ // STEP_START em4
+ SearchResult res5 = db.FT().Search(
+ "idx:bicycle",
+ new Query("@description:\"rough terrain\"")
+ );
+ Console.WriteLine(res5.TotalResults); // >>> 1
+ // STEP_END
+
+ // Tests for 'em4' step.
+ // REMOVE_START
+ Assert.Equal(1, res5.TotalResults);
+ // REMOVE_END
+
+
+ // HIDE_START
+ }
+}
+// HIDE_END
+
From 0171221a5911841084a6ba1655cd72e19cadea43 Mon Sep 17 00:00:00 2001
From: atakavci <58048133+atakavci@users.noreply.github.com>
Date: Tue, 1 Oct 2024 13:31:08 +0300
Subject: [PATCH 10/22] Deprecate Triggers and Functions (#343)
deprecate T&F
---
src/NRedisStack/Gears/GearsCommandBuilder.cs | 5 +
src/NRedisStack/Gears/GearsCommands.cs | 7 +-
src/NRedisStack/Gears/GearsCommandsAsync.cs | 5 +
tests/NRedisStack.Tests/Gears/GearsTests.cs | 210 -------------------
4 files changed, 16 insertions(+), 211 deletions(-)
delete mode 100644 tests/NRedisStack.Tests/Gears/GearsTests.cs
diff --git a/src/NRedisStack/Gears/GearsCommandBuilder.cs b/src/NRedisStack/Gears/GearsCommandBuilder.cs
index 5af745ba..8dec9026 100644
--- a/src/NRedisStack/Gears/GearsCommandBuilder.cs
+++ b/src/NRedisStack/Gears/GearsCommandBuilder.cs
@@ -3,8 +3,10 @@
namespace NRedisStack
{
+ [Obsolete]
public static class GearsCommandBuilder
{
+ [Obsolete]
public static SerializedCommand TFunctionLoad(string libraryCode, bool replace = false, string? config = null)
{
var args = new List
-
\ No newline at end of file
+
diff --git a/tests/NRedisStack.Tests/NRedisStack.Tests.csproj b/tests/NRedisStack.Tests/NRedisStack.Tests.csproj
index 595a01a6..7521af79 100644
--- a/tests/NRedisStack.Tests/NRedisStack.Tests.csproj
+++ b/tests/NRedisStack.Tests/NRedisStack.Tests.csproj
@@ -20,11 +20,11 @@
all
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
From dfc75d24d103d566fc17deda692e63110e9f4e91 Mon Sep 17 00:00:00 2001
From: atakavci <58048133+atakavci@users.noreply.github.com>
Date: Tue, 31 Dec 2024 12:44:48 +0300
Subject: [PATCH 22/22] Fix failing docuement.load in query results with an
expired doc (#357)
* fix failing docuement load in query results with an expired doc
* IsCompletedSuccessfully" is *not* available in all test envs
* set test case for non cluster env
---
src/NRedisStack/Search/Document.cs | 4 ++
tests/NRedisStack.Tests/Search/SearchTests.cs | 50 ++++++++++++++++++-
2 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/src/NRedisStack/Search/Document.cs b/src/NRedisStack/Search/Document.cs
index 3223054f..c8f9dec5 100644
--- a/src/NRedisStack/Search/Document.cs
+++ b/src/NRedisStack/Search/Document.cs
@@ -31,6 +31,10 @@ public static Document Load(string id, double score, byte[]? payload, RedisValue
{
Document ret = new Document(id, score, payload);
if (fields == null) return ret;
+ if (fields.Length == 1 && fields[0].IsNull)
+ {
+ return ret;
+ }
for (int i = 0; i < fields.Length; i += 2)
{
string fieldName = fields[i]!;
diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs
index a5acfb68..c19c7457 100644
--- a/tests/NRedisStack.Tests/Search/SearchTests.cs
+++ b/tests/NRedisStack.Tests/Search/SearchTests.cs
@@ -11,7 +11,6 @@
namespace NRedisStack.Tests.Search;
-
public class SearchTests : AbstractNRedisStackTest, IDisposable
{
// private readonly string key = "SEARCH_TESTS";
@@ -3313,4 +3312,53 @@ public void TestNumericLogicalOperatorsInDialect4()
Assert.Equal(1, ft.Search(index, new Query("@version:[123 123] | @id:[456 7890]")).TotalResults);
Assert.Equal(1, ft.Search(index, new Query("@version==123 @id==456").Dialect(4)).TotalResults);
}
+
+ [Fact]
+ public void TestDocumentLoad_Issue352()
+ {
+ Document d = Document.Load("1", 0.5, null, new RedisValue[] { RedisValue.Null });
+ Assert.Empty(d.GetProperties().ToList());
+ }
+
+ [SkipIfRedis(Is.OSSCluster)]
+ public void TestDocumentLoadWithDB_Issue352()
+ {
+ IDatabase db = redisFixture.Redis.GetDatabase();
+ db.Execute("FLUSHALL");
+ var ft = db.FT();
+
+ Schema sc = new Schema().AddTextField("first", 1.0).AddTextField("last", 1.0).AddNumericField("age");
+ Assert.True(ft.Create(index, FTCreateParams.CreateParams(), sc));
+
+ Document droppedDocument = null;
+ int numberOfAttempts = 0;
+ do
+ {
+ db.HashSet("student:1111", new HashEntry[] { new("first", "Joe"), new("last", "Dod"), new("age", 18) });
+
+ Assert.True(db.KeyExpire("student:1111", TimeSpan.FromMilliseconds(500)));
+
+ Boolean cancelled = false;
+ Task searchTask = Task.Run(() =>
+ {
+ for (int i = 0; i < 100000; i++)
+ {
+ SearchResult result = ft.Search(index, new Query());
+ List docs = result.Documents;
+ if (docs.Count == 0 || cancelled)
+ {
+ break;
+ }
+ else if (docs[0].GetProperties().ToList().Count == 0)
+ {
+ droppedDocument = docs[0];
+ }
+ }
+ });
+ Task.WhenAny(searchTask, Task.Delay(1000)).GetAwaiter().GetResult();
+ Assert.True(searchTask.IsCompleted);
+ Assert.Null(searchTask.Exception);
+ cancelled = true;
+ } while (droppedDocument == null && numberOfAttempts++ < 3);
+ }
}