Skip to content

Commit da0e77c

Browse files
committed
fix(doctests): update imports and replace deprecated disconnect with close
- Replace SchemaFieldTypes/VectorAlgorithms with SCHEMA_FIELD_TYPE/SCHEMA_VECTOR_FIELD_ALGORITHM - Replace client.disconnect() with client.close() for consistent deprecation handling - Update query-combined.js, query-em.js, query-ft.js, and query-geo.js
1 parent 8655aa1 commit da0e77c

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

doctests/query-combined.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import assert from 'node:assert';
44
import fs from 'node:fs';
55
import { createClient } from 'redis';
6-
import { SchemaFieldTypes, VectorAlgorithms } from '@redis/search';
6+
import { SCHEMA_FIELD_TYPE, SCHEMA_VECTOR_FIELD_ALGORITHM } from '@redis/search';
77
import { pipeline } from '@xenova/transformers';
88

99
function float32Buffer(arr) {
@@ -30,7 +30,6 @@ async function embedText(sentence) {
3030
return embedding;
3131
}
3232

33-
let query = 'Bike for small kids';
3433
let vector_query = float32Buffer(await embedText('That is a very happy person'));
3534

3635
const client = createClient();
@@ -39,21 +38,21 @@ await client.connect().catch(console.error);
3938
// create index
4039
await client.ft.create('idx:bicycle', {
4140
'$.description': {
42-
type: SchemaFieldTypes.TEXT,
41+
type: SCHEMA_FIELD_TYPE.TEXT,
4342
AS: 'description'
4443
},
4544
'$.condition': {
46-
type: SchemaFieldTypes.TAG,
45+
type: SCHEMA_FIELD_TYPE.TAG,
4746
AS: 'condition'
4847
},
4948
'$.price': {
50-
type: SchemaFieldTypes.NUMERIC,
49+
type: SCHEMA_FIELD_TYPE.NUMERIC,
5150
AS: 'price'
5251
},
5352
'$.description_embeddings': {
54-
type: SchemaFieldTypes.VECTOR,
53+
type: SCHEMA_FIELD_TYPE.VECTOR,
5554
TYPE: 'FLOAT32',
56-
ALGORITHM: VectorAlgorithms.FLAT,
55+
ALGORITHM: SCHEMA_VECTOR_FIELD_ALGORITHM.FLAT,
5756
DIM: 384,
5857
DISTANCE_METRIC: 'COSINE',
5958
AS: 'vector',
@@ -188,5 +187,5 @@ assert.strictEqual(res7.total, 2);
188187
// REMOVE_START
189188
// destroy index and data
190189
await client.ft.dropIndex('idx:bicycle', { DD: true });
191-
await client.disconnect();
190+
await client.close();
192191
// REMOVE_END

doctests/query-em.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// HIDE_START
33
import assert from 'node:assert';
44
import fs from 'node:fs';
5-
import { createClient, SchemaFieldTypes, AggregateGroupByReducers, AggregateSteps} from 'redis';
5+
import { createClient, SCHEMA_FIELD_TYPE } from 'redis';
66

77
const client = createClient();
88

@@ -11,15 +11,15 @@ await client.connect().catch(console.error);
1111
// create index
1212
await client.ft.create('idx:bicycle', {
1313
'$.description': {
14-
type: SchemaFieldTypes.TEXT,
14+
type: SCHEMA_FIELD_TYPE.TEXT,
1515
AS: 'description'
1616
},
1717
'$.price': {
18-
type: SchemaFieldTypes.NUMERIC,
18+
type: SCHEMA_FIELD_TYPE.NUMERIC,
1919
AS: 'price'
2020
},
2121
'$.condition': {
22-
type: SchemaFieldTypes.TAG,
22+
type: SCHEMA_FIELD_TYPE.TAG,
2323
AS: 'condition'
2424
}
2525
}, {
@@ -85,7 +85,7 @@ assert.strictEqual(res5.total, 5);
8585
// STEP_START em3
8686
await client.ft.create('idx:email', {
8787
'$.email': {
88-
type: SchemaFieldTypes.TAG,
88+
type: SCHEMA_FIELD_TYPE.TAG,
8989
AS: 'email'
9090
}
9191
}, {
@@ -117,5 +117,5 @@ assert.strictEqual(res7.total, 1);
117117
// REMOVE_START
118118
// destroy index and data
119119
await client.ft.dropIndex('idx:bicycle', { DD: true });
120-
await client.disconnect();
120+
await client.close();
121121
// REMOVE_END

doctests/query-ft.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// HIDE_START
33
import assert from 'node:assert';
44
import fs from 'node:fs';
5-
import { createClient, SchemaFieldTypes, AggregateGroupByReducers, AggregateSteps} from 'redis';
5+
import { createClient, SCHEMA_FIELD_TYPE } from 'redis';
66

77
const client = createClient();
88

@@ -11,15 +11,15 @@ await client.connect().catch(console.error);
1111
// create index
1212
await client.ft.create('idx:bicycle', {
1313
'$.model': {
14-
type: SchemaFieldTypes.TEXT,
14+
type: SCHEMA_FIELD_TYPE.TEXT,
1515
AS: 'model'
1616
},
1717
'$.brand': {
18-
type: SchemaFieldTypes.TEXT,
18+
type: SCHEMA_FIELD_TYPE.TEXT,
1919
AS: 'brand'
2020
},
2121
'$.description': {
22-
type: SchemaFieldTypes.TEXT,
22+
type: SCHEMA_FIELD_TYPE.TEXT,
2323
AS: 'description'
2424
}
2525
}, {
@@ -80,5 +80,5 @@ assert.strictEqual(res5.total, 1);
8080
// REMOVE_START
8181
// destroy index and data
8282
await client.ft.dropIndex('idx:bicycle', { DD: true });
83-
await client.disconnect();
83+
await client.close();
8484
// REMOVE_END

doctests/query-geo.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import assert from 'node:assert';
44
import fs from 'node:fs';
55
import { createClient } from 'redis';
6-
import { SchemaFieldTypes } from '@redis/search';
6+
import { SCHEMA_FIELD_TYPE } from '@redis/search';
77

88
const client = createClient();
99

@@ -12,11 +12,11 @@ await client.connect().catch(console.error);
1212
// create index
1313
await client.ft.create('idx:bicycle', {
1414
'$.store_location': {
15-
type: SchemaFieldTypes.GEO,
15+
type: SCHEMA_FIELD_TYPE.GEO,
1616
AS: 'store_location'
1717
},
1818
'$.pickup_zone': {
19-
type: SchemaFieldTypes.GEOSHAPE,
19+
type: SCHEMA_FIELD_TYPE.GEOSHAPE,
2020
AS: 'pickup_zone'
2121
}
2222
}, {
@@ -78,5 +78,5 @@ assert.strictEqual(res3.total, 5);
7878
// REMOVE_START
7979
// destroy index and data
8080
await client.ft.dropIndex('idx:bicycle', { DD: true });
81-
await client.disconnect();
81+
await client.close();
8282
// REMOVE_END

0 commit comments

Comments
 (0)