Skip to content

Commit 8ea2123

Browse files
committed
Merge branch 'master' of github.com:redis/node-redis into sharded-pubusb
2 parents 298697a + 9dccd9a commit 8ea2123

File tree

7 files changed

+83
-52
lines changed

7 files changed

+83
-52
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Node-Redis
22

3-
[![Tests](https://img.shields.io/github/workflow/status/redis/node-redis/Tests/master.svg?label=tests)](https://github.com/redis/node-redis/actions/workflows/tests.yml)
3+
[![Tests](https://img.shields.io/github/actions/workflow/status/redis/node-redis/tests.yml?branch=master)](https://github.com/redis/node-redis/actions/workflows/tests.yml)
44
[![Coverage](https://codecov.io/gh/redis/node-redis/branch/master/graph/badge.svg?token=xcfqHhJC37)](https://codecov.io/gh/redis/node-redis)
55
[![License](https://img.shields.io/github/license/redis/node-redis.svg)](https://github.com/redis/node-redis/blob/master/LICENSE)
66

@@ -64,6 +64,8 @@ createClient({
6464

6565
You can also use discrete parameters, UNIX sockets, and even TLS to connect. Details can be found in the [client configuration guide](./docs/client-configuration.md).
6666

67+
To check if the the client is connected and ready to send commands, use `client.isReady` which returns a boolean. `client.isOpen` is also available. This returns `true` when the client's underlying socket is open, and `false` when it isn't (for example when the client is still connecting or reconnecting after a network error).
68+
6769
### Redis Commands
6870

6971
There is built-in support for all of the [out-of-the-box Redis commands](https://redis.io/commands). They are exposed using the raw Redis command names (`HSET`, `HGETALL`, etc.) and a friendlier camel-cased version (`hSet`, `hGetAll`, etc.):

examples/README.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,33 @@
22

33
This folder contains example scripts showing how to use Node Redis in different scenarios.
44

5-
| File Name | Description |
6-
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
7-
| `blocking-list-pop.js` | Block until an element is pushed to a list |
8-
| `bloom-filter.js` | Space efficient set membership checks with a [Bloom Filter](https://en.wikipedia.org/wiki/Bloom_filter) using [RedisBloom](https://redisbloom.io) |
9-
| `command-with-modifiers.js` | Define a script that allows to run a command with several modifiers |
10-
| `connect-as-acl-user.js` | Connect to Redis 6 using an ACL user |
11-
| `connect-to-cluster.js` | Connect to Redis cluster |
12-
| `count-min-sketch.js` | Estimate the frequency of a given event using the [RedisBloom](https://redisbloom.io) Count-Min Sketch |
13-
| `cuckoo-filter.js` | Space efficient set membership checks with a [Cuckoo Filter](https://en.wikipedia.org/wiki/Cuckoo_filter) using [RedisBloom](https://redisbloom.io) |
14-
| `get-server-time.js` | Get the time from the Redis server |
15-
| `hyperloglog.js` | Showing use of Hyperloglog commands [PFADD, PFCOUNT and PFMERGE](https://redis.io/commands/?group=hyperloglog) |
16-
| `lua-multi-incr.js` | Define a custom lua script that allows you to perform INCRBY on multiple keys |
17-
| `managing-json.js` | Store, retrieve and manipulate JSON data atomically with [RedisJSON](https://redisjson.io/) |
18-
| `pubsub-publisher.js` | Adds multiple messages on 2 different channels messages to Redis |
19-
| `pubsub-subscriber.js` | Reads messages from channels using `PSUBSCRIBE` command |
20-
| `search-hashes.js` | Uses [RediSearch](https://redisearch.io) to index and search data in hashes |
21-
| `search-json.js` | Uses [RediSearch](https://redisearch.io/) and [RedisJSON](https://redisjson.io/) to index and search JSON data |
22-
| `set-scan.js` | An example script that shows how to use the SSCAN iterator functionality |
23-
| `sorted-set.js` | Add members with scores to a Sorted Set and retrieve them using the ZSCAN iteractor functionality |
24-
| `stream-producer.js` | Adds entries to a [Redis Stream](https://redis.io/topics/streams-intro) using the `XADD` command |
25-
| `stream-consumer.js` | Reads entries from a [Redis Stream](https://redis.io/topics/streams-intro) using the blocking `XREAD` command |
26-
| `time-series.js` | Create, populate and query timeseries data with [Redis Timeseries](https://redistimeseries.io) |
27-
| `topk.js` | Use the [RedisBloom](https://redisbloom.io) TopK to track the most frequently seen items. |
28-
| `stream-consumer-group.js` | Reads entties from a [Redis Stream](https://redis.io/topics/streams-intro) as part of a consumer group using the blocking `XREADGROUP` command |
29-
| `transaction-with-watch.js` | An Example of [Redis transaction](https://redis.io/docs/manual/transactions) with `WATCH` command on isolated connection with optimistic locking |
5+
| File Name | Description |
6+
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
7+
| `blocking-list-pop.js` | Block until an element is pushed to a list. |
8+
| `bloom-filter.js` | Space efficient set membership checks with a [Bloom Filter](https://en.wikipedia.org/wiki/Bloom_filter) using [RedisBloom](https://redisbloom.io). |
9+
| `check-connection-status.js` | Check the client's connection status. |
10+
| `command-with-modifiers.js` | Define a script that allows to run a command with several modifiers. |
11+
| `connect-as-acl-user.js` | Connect to Redis 6 using an ACL user. |
12+
| `connect-to-cluster.js` | Connect to a Redis cluster. |
13+
| `count-min-sketch.js` | Estimate the frequency of a given event using the [RedisBloom](https://redisbloom.io) Count-Min Sketch. |
14+
| `cuckoo-filter.js` | Space efficient set membership checks with a [Cuckoo Filter](https://en.wikipedia.org/wiki/Cuckoo_filter) using [RedisBloom](https://redisbloom.io). |
15+
| `get-server-time.js` | Get the time from the Redis server. |
16+
| `hyperloglog.js` | Showing use of Hyperloglog commands [PFADD, PFCOUNT and PFMERGE](https://redis.io/commands/?group=hyperloglog). |
17+
| `lua-multi-incr.js` | Define a custom lua script that allows you to perform INCRBY on multiple keys. |
18+
| `managing-json.js` | Store, retrieve and manipulate JSON data atomically with [RedisJSON](https://redisjson.io/). |
19+
| `pubsub-publisher.js` | Adds multiple messages on 2 different channels messages to Redis. |
20+
| `pubsub-subscriber.js` | Reads messages from channels using `PSUBSCRIBE` command. |
21+
| `search-hashes.js` | Uses [RediSearch](https://redisearch.io) to index and search data in hashes. |
22+
| `search-json.js` | Uses [RediSearch](https://redisearch.io/) and [RedisJSON](https://redisjson.io/) to index and search JSON data. |
23+
| `set-scan.js` | An example script that shows how to use the SSCAN iterator functionality. |
24+
| `sorted-set.js` | Add members with scores to a Sorted Set and retrieve them using the ZSCAN iteractor functionality. |
25+
| `stream-producer.js` | Adds entries to a [Redis Stream](https://redis.io/topics/streams-intro) using the `XADD` command. |
26+
| `stream-consumer.js` | Reads entries from a [Redis Stream](https://redis.io/topics/streams-intro) using the blocking `XREAD` command. |
27+
| `time-series.js` | Create, populate and query timeseries data with [Redis Timeseries](https://redistimeseries.io). |
28+
| `topk.js` | Use the [RedisBloom](https://redisbloom.io) TopK to track the most frequently seen items. |
29+
| `stream-consumer-group.js` | Reads entries from a [Redis Stream](https://redis.io/topics/streams-intro) as part of a consumer group using the blocking `XREADGROUP` command. |
30+
| `tranaaction-with-arbitrary-commands.js` | Mix and match supported commands with arbitrary command strings in a Redis transaction. |
31+
| `transaction-with-watch.js` | An Example of [Redis transaction](https://redis.io/docs/manual/transactions) with `WATCH` command on isolated connection with optimistic locking. |
3032

3133
## Contributing
3234

examples/check-connection-status.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Check the connection status of the Redis client instance.
2+
import { createClient } from 'redis';
3+
4+
const client = createClient();
5+
6+
console.log('Before client.connect()...');
7+
8+
// isOpen will return False here as the client's socket is not open yet.
9+
// isReady will return False here, client is not yet ready to use.
10+
console.log(`client.isOpen: ${client.isOpen}, client.isReady: ${client.isReady}`);
11+
12+
// Begin connection process...
13+
const connectPromise = client.connect();
14+
15+
console.log('After client.connect()...');
16+
17+
// isOpen will return True here as the client's socket is open now.
18+
// isReady will return False here as the promise hasn't resolved yet.
19+
console.log(`client.isOpen: ${client.isOpen}, client.isReady: ${client.isReady}`);
20+
21+
await connectPromise;
22+
console.log('Afer connectPromise has resolved...');
23+
24+
// isOpen will return True here as the client's socket is open now.
25+
// isReady will return True here, client is ready to use.
26+
console.log(`client.isOpen: ${client.isOpen}, client.isReady: ${client.isReady}`);
27+
28+
await client.quit();

packages/client/lib/commands/SET.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,45 @@ describe('SET', () => {
1313

1414
it('number', () => {
1515
assert.deepEqual(
16-
transformArguments('key', 1),
17-
['SET', 'key', '1']
16+
transformArguments('key', 0),
17+
['SET', 'key', '0']
1818
);
1919
});
2020

2121
describe('TTL', () => {
2222
it('with EX', () => {
2323
assert.deepEqual(
2424
transformArguments('key', 'value', {
25-
EX: 1
25+
EX: 0
2626
}),
27-
['SET', 'key', 'value', 'EX', '1']
27+
['SET', 'key', 'value', 'EX', '0']
2828
);
2929
});
3030

3131
it('with PX', () => {
3232
assert.deepEqual(
3333
transformArguments('key', 'value', {
34-
PX: 1
34+
PX: 0
3535
}),
36-
['SET', 'key', 'value', 'PX', '1']
36+
['SET', 'key', 'value', 'PX', '0']
3737
);
3838
});
3939

4040
it('with EXAT', () => {
4141
assert.deepEqual(
4242
transformArguments('key', 'value', {
43-
EXAT: 1
43+
EXAT: 0
4444
}),
45-
['SET', 'key', 'value', 'EXAT', '1']
45+
['SET', 'key', 'value', 'EXAT', '0']
4646
);
4747
});
4848

4949
it('with PXAT', () => {
5050
assert.deepEqual(
5151
transformArguments('key', 'value', {
52-
PXAT: 1
52+
PXAT: 0
5353
}),
54-
['SET', 'key', 'value', 'PXAT', '1']
54+
['SET', 'key', 'value', 'PXAT', '0']
5555
);
5656
});
5757

packages/client/lib/commands/SET.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ export function transformArguments(
3535
typeof value === 'number' ? value.toString() : value
3636
];
3737

38-
if (options?.EX) {
38+
if (options?.EX !== undefined) {
3939
args.push('EX', options.EX.toString());
40-
} else if (options?.PX) {
40+
} else if (options?.PX !== undefined) {
4141
args.push('PX', options.PX.toString());
42-
} else if (options?.EXAT) {
42+
} else if (options?.EXAT !== undefined) {
4343
args.push('EXAT', options.EXAT.toString());
44-
} else if (options?.PXAT) {
44+
} else if (options?.PXAT !== undefined) {
4545
args.push('PXAT', options.PXAT.toString());
4646
} else if (options?.KEEPTTL) {
4747
args.push('KEEPTTL');

packages/search/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ Before we can perform any searches, we need to tell RediSearch how to index our
1818
await client.ft.create('idx:animals', {
1919
name: {
2020
type: SchemaFieldTypes.TEXT,
21-
sortable: true
21+
SORTABLE: true
2222
},
23-
species: SchemaFieldTypes.TAG,
24-
age: SchemaFieldTypes.NUMERIC
25-
}, {
26-
ON: 'HASH',
27-
PREFIX: 'noderedis:animals'
28-
}
29-
);
23+
species: SchemaFieldTypes.TAG,
24+
age: SchemaFieldTypes.NUMERIC
25+
}, {
26+
ON: 'HASH',
27+
PREFIX: 'noderedis:animals'
28+
});
3029
```
3130

3231
See the [`FT.CREATE` documentation](https://oss.redis.com/redisearch/Commands/#ftcreate) for information about the different field types and additional options.

packages/search/lib/commands/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ export enum RedisSearchLanguages {
134134

135135
export type PropertyName = `${'@' | '$.'}${string}`;
136136

137-
export type SortByProperty = PropertyName | {
138-
BY: PropertyName;
137+
export type SortByProperty = string | {
138+
BY: string;
139139
DIRECTION?: 'ASC' | 'DESC';
140140
};
141141

@@ -187,15 +187,15 @@ export enum SchemaFieldTypes {
187187

188188
type CreateSchemaField<
189189
T extends SchemaFieldTypes,
190-
E = Record<keyof any, any>
190+
E = Record<PropertyKey, unknown>
191191
> = T | ({
192192
type: T;
193193
AS?: string;
194194
} & E);
195195

196196
type CreateSchemaCommonField<
197197
T extends SchemaFieldTypes,
198-
E = Record<string, never>
198+
E = Record<PropertyKey, unknown>
199199
> = CreateSchemaField<
200200
T,
201201
({

0 commit comments

Comments
 (0)