Skip to content

Commit

Permalink
fix: use branded UnixTimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Nov 9, 2024
1 parent 40800b7 commit 53ad101
Show file tree
Hide file tree
Showing 3 changed files with 476 additions and 535 deletions.
6 changes: 3 additions & 3 deletions src/redisClient.manual.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { localTime } from '@naturalcycles/js-lib'
import { localTime, UnixTimestamp } from '@naturalcycles/js-lib'
import { RedisClient } from './redisClient'

let client: RedisClient
Expand Down Expand Up @@ -152,8 +152,8 @@ describe('hashmap functions', () => {
test.skip('hsetWithTTL should set the fields with expiry', async () => {
const now = localTime.now().unix

await client.hsetWithTTL('test:key', { foo1: 'bar' }, now + 1000)
await client.hsetWithTTL('test:key', { foo2: 'bar' }, now - 1)
await client.hsetWithTTL('test:key', { foo1: 'bar' }, (now + 1000) as UnixTimestamp)
await client.hsetWithTTL('test:key', { foo2: 'bar' }, (now - 1) as UnixTimestamp)

const result = await client.hgetall('test:key')
expect(result).toEqual({ foo1: 'bar' })
Expand Down
12 changes: 3 additions & 9 deletions src/redisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import {
NullableString,
Promisable,
StringMap,
UnixTimestampNumber,
UnixTimestamp,
} from '@naturalcycles/js-lib'
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
// eslint-disable-next-line import-x/no-duplicates
import type { Redis, RedisOptions } from 'ioredis'
// eslint-disable-next-line import-x/no-duplicates
import type * as RedisLib from 'ioredis'
import type { ScanStreamOptions } from 'ioredis/built/types'
import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander'
Expand Down Expand Up @@ -181,16 +179,12 @@ export class RedisClient implements CommonClient {
async setWithTTL(
key: string,
value: string | number | Buffer,
expireAt: UnixTimestampNumber,
expireAt: UnixTimestamp,
): Promise<void> {
await this.redis().set(key, value, 'EXAT', expireAt)
}

async hsetWithTTL(
_key: string,
_value: AnyObject,
_expireAt: UnixTimestampNumber,
): Promise<void> {
async hsetWithTTL(_key: string, _value: AnyObject, _expireAt: UnixTimestamp): Promise<void> {
throw new Error('Not supported until Redis 7.4.0')
// const valueKeys = Object.keys(value)
// const numberOfKeys = valueKeys.length
Expand Down
Loading

0 comments on commit 53ad101

Please sign in to comment.