Skip to content

Commit 7e04f58

Browse files
author
Adan
committed
Node: added persist command.
1 parent 54bf451 commit 7e04f58

File tree

9 files changed

+72
-10
lines changed

9 files changed

+72
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
* Python, Node: Added TYPE command ([#945](https://github.com/aws/glide-for-redis/pull/945), [#980](https://github.com/aws/glide-for-redis/pull/980))
77
* Python, Node: Added HLEN command ([#944](https://github.com/aws/glide-for-redis/pull/944), [#981](https://github.com/aws/glide-for-redis/pull/981))
88
* Python, Node: Added ZCOUNT command ([#878](https://github.com/aws/glide-for-redis/pull/878)) ([#909](https://github.com/aws/glide-for-redis/pull/909))
9-
* Python: Added ECHO command ([#953](https://github.com/aws/glide-for-redis/pull/953))
9+
* Python, Node: Added ECHO command ([#953](https://github.com/aws/glide-for-redis/pull/953), [#1010](https://github.com/aws/glide-for-redis/pull/1010))
1010
* Python, Node: Added ZPOPMIN command ([#975](https://github.com/aws/glide-for-redis/pull/975), [#1008](https://github.com/aws/glide-for-redis/pull/1008))
1111
* Node: Added STRLEN command ([#993](https://github.com/aws/glide-for-redis/pull/993))
1212
* Node: Added LINDEX command ([#999](https://github.com/aws/glide-for-redis/pull/999))
1313
* Python, Node: Added ZPOPMAX command ([#996](https://github.com/aws/glide-for-redis/pull/996), [#1009](https://github.com/aws/glide-for-redis/pull/1009))
1414
* Python: Added ZRANGE command ([#906](https://github.com/aws/glide-for-redis/pull/906))
1515
* Python, Node: Added PTTL command ([#1036](https://github.com/aws/glide-for-redis/pull/1036), [#1082](https://github.com/aws/glide-for-redis/pull/1082))
16+
* Node: Added HVAL command ([#1022](https://github.com/aws/glide-for-redis/pull/1022))
17+
* Node: Added PERSIST command ([#1023](https://github.com/aws/glide-for-redis/pull/1023))
1618

1719
#### Features
1820

glide-core/src/client/value_conversion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub(crate) fn expected_type_for_cmd(cmd: &Cmd) -> Option<ExpectedReturnType> {
200200
}
201201
b"INCRBYFLOAT" | b"HINCRBYFLOAT" => Some(ExpectedReturnType::Double),
202202
b"HEXISTS" | b"HSETNX" | b"EXPIRE" | b"EXPIREAT" | b"PEXPIRE" | b"PEXPIREAT"
203-
| b"SISMEMBER" => Some(ExpectedReturnType::Boolean),
203+
| b"SISMEMBER" | b"PERSIST" => Some(ExpectedReturnType::Boolean),
204204
b"SMEMBERS" => Some(ExpectedReturnType::Set),
205205
b"ZSCORE" => Some(ExpectedReturnType::DoubleOrNull),
206206
b"ZPOPMIN" | b"ZPOPMAX" => Some(ExpectedReturnType::MapOfStringToDouble),

glide-core/src/protobuf/redis_request.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ enum RequestType {
128128
Hvals = 84;
129129
PTTL = 85;
130130
ZRemRangeByRank = 86;
131+
Persist = 87;
131132
}
132133

133134
message Command {

glide-core/src/socket_listener.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ fn get_command(request: &Command) -> Option<Cmd> {
358358
RequestType::Hvals => Some(cmd("HVALS")),
359359
RequestType::PTTL => Some(cmd("PTTL")),
360360
RequestType::ZRemRangeByRank => Some(cmd("ZREMRANGEBYRANK")),
361+
RequestType::Persist => Some(cmd("PERSIST")),
361362
}
362363
}
363364

node/src/BaseClient.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
createMSet,
4848
createPExpire,
4949
createPExpireAt,
50+
createPersist,
5051
createPttl,
5152
createRPop,
5253
createRPush,
@@ -1176,7 +1177,7 @@ export class BaseClient {
11761177
* Both `start` and `end` are zero-based indexes with 0 being the element with the lowest score.
11771178
* These indexes can be negative numbers, where they indicate offsets starting at the element with the highest score.
11781179
* See https://redis.io/commands/zremrangebyrank/ for more details.
1179-
*
1180+
*
11801181
* @param key - The key of the sorted set.
11811182
* @param start - The starting point of the range.
11821183
* @param end - The end of the range.
@@ -1185,7 +1186,11 @@ export class BaseClient {
11851186
* If `end` exceeds the actual end of the sorted set, the range will stop at the actual end of the sorted set.
11861187
* If `key` does not exist 0 will be returned.
11871188
*/
1188-
public zremRangeByRank(key: string, start: number, end: number): Promise<number> {
1189+
public zremRangeByRank(
1190+
key: string,
1191+
start: number,
1192+
end: number,
1193+
): Promise<number> {
11891194
return this.createWritePromise(createZremRangeByRank(key, start, end));
11901195
}
11911196

@@ -1212,6 +1217,17 @@ export class BaseClient {
12121217
return this.createWritePromise(createLindex(key, index));
12131218
}
12141219

1220+
/** Remove the existing timeout on `key`, turning the key from volatile (a key with an expire set) to
1221+
* persistent (a key that will never expire as no timeout is associated).
1222+
* See https://redis.io/commands/persist/ for more details.
1223+
*
1224+
* @param key - The key to remove the existing timeout on.
1225+
* @returns `false` if `key` does not exist or does not have an associated timeout, `true` if the timeout has been removed.
1226+
*/
1227+
public persist(key: string): Promise<boolean> {
1228+
return this.createWritePromise(createPersist(key));
1229+
}
1230+
12151231
/**
12161232
* @internal
12171233
*/

node/src/Commands.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,18 @@ export function createPttl(key: string): redis_request.Command {
897897
export function createZremRangeByRank(
898898
key: string,
899899
start: number,
900-
stop: number
900+
stop: number,
901901
): redis_request.Command {
902902
return createCommand(RequestType.ZRemRangeByRank, [
903903
key,
904904
start.toString(),
905905
stop.toString(),
906906
]);
907907
}
908+
909+
/**
910+
* @internal
911+
*/
912+
export function createPersist(key: string): redis_request.Command {
913+
return createCommand(RequestType.Persist, [key]);
914+
}

node/src/Transaction.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
createMSet,
4949
createPExpire,
5050
createPExpireAt,
51+
createPersist,
5152
createPing,
5253
createPttl,
5354
createRPop,
@@ -941,11 +942,11 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
941942
* Both `start` and `end` are zero-based indexes with 0 being the element with the lowest score.
942943
* These indexes can be negative numbers, where they indicate offsets starting at the element with the highest score.
943944
* See https://redis.io/commands/zremrangebyrank/ for more details.
944-
*
945+
*
945946
* @param key - The key of the sorted set.
946947
* @param start - The starting point of the range.
947948
* @param end - The end of the range.
948-
*
949+
*
949950
* Command Response - The number of members removed.
950951
* If `start` exceeds the end of the sorted set, or if `start` is greater than `end`, 0 returned.
951952
* If `end` exceeds the actual end of the sorted set, the range will stop at the actual end of the sorted set.
@@ -955,6 +956,18 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
955956
return this.addAndReturn(createZremRangeByRank(key, start, end));
956957
}
957958

959+
/** Remove the existing timeout on `key`, turning the key from volatile (a key with an expire set) to
960+
* persistent (a key that will never expire as no timeout is associated).
961+
* See https://redis.io/commands/persist/ for more details.
962+
*
963+
* @param key - The key to remove the existing timeout on.
964+
*
965+
* Command Response - `false` if `key` does not exist or does not have an associated timeout, `true` if the timeout has been removed.
966+
*/
967+
public persist(key: string): T {
968+
return this.addAndReturn(createPersist(key));
969+
}
970+
958971
/** Executes a single command, without checking inputs. Every part of the command, including subcommands,
959972
* should be added as a separate value in args.
960973
*

node/tests/SharedTests.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,11 +1705,26 @@ export function runBaseTests<Context>(config: {
17051705
expect(await client.zremRangeByRank(key, 0, 1)).toEqual(2);
17061706
expect(await client.zremRangeByRank(key, 0, 10)).toEqual(1);
17071707
expect(
1708-
await client.zremRangeByRank("nonExistingKey", 0, -1)
1708+
await client.zremRangeByRank("nonExistingKey", 0, -1),
17091709
).toEqual(0);
17101710
}, protocol);
17111711
},
1712-
config.timeout
1712+
config.timeout,
1713+
);
1714+
1715+
it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
1716+
`persist test_%p`,
1717+
async (protocol) => {
1718+
await runTest(async (client: BaseClient) => {
1719+
const key = uuidv4();
1720+
expect(await client.set(key, "foo")).toEqual("OK");
1721+
expect(await client.persist(key)).toEqual(false);
1722+
1723+
expect(await client.expire(key, 10)).toEqual(true);
1724+
expect(await client.persist(key)).toEqual(true);
1725+
}, protocol);
1726+
},
1727+
config.timeout,
17131728
);
17141729
}
17151730

node/tests/TestUtilities.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export function transactionTest(
7070
args.push("string");
7171
baseTransaction.echo(value);
7272
args.push(value);
73+
baseTransaction.persist(key1);
74+
args.push(false);
7375
baseTransaction.set(key2, "baz", {
7476
returnOldValue: true,
7577
});
@@ -135,7 +137,12 @@ export function transactionTest(
135137
args.push(1);
136138
baseTransaction.smembers(key7);
137139
args.push(["bar"]);
138-
baseTransaction.zadd(key8, { member1: 1, member2: 2, member3: 3.5, member4: 4 });
140+
baseTransaction.zadd(key8, {
141+
member1: 1,
142+
member2: 2,
143+
member3: 3.5,
144+
member4: 4,
145+
});
139146
args.push(4);
140147
baseTransaction.zaddIncr(key8, "member2", 1);
141148
args.push(3);

0 commit comments

Comments
 (0)