我有这堂课
import Redis = require('ioredis')
import { Mutex } from 'redis-semaphore'
const LOCKED_STREAM_IDS_REDIS_KEY = 'ghost_stream_merger_locked_stream_ids'
const NOT_FULL_STREAM_IDS_REDIS_KEY = 'ghost_stream_merger_not_full_stream_ids'
const MUTEX_NAME = 'ghost_stream_merger'
export interface IRedisCache {
redisClient : any
mutex : Mutex
getLockedStreamIds() : Promise<string[]>
addLockedStreamIds(streamIds : string[]) : Promise<number>
removeLockedStreamIds(streamIds : string[]) : Promise<number>
deleteLockedStreamIds() : Promise<number>
getNotFullStreamIds() : Promise<string[]>
addNotFullStreamIds(streamIds : string[]) : Promise<number>
removeNotFullStreamIds(streamIds : string[]) : Promise<number>
deleteNotFullStreamIds() : Promise<number>
}
export default class RedisCache implements IRedisCache {
redisClient : any
mutex : Mutex
constructor(redisConfig : any) {
this.redisClient = new Redis(redisConfig)
this.mutex = new Mutex(this.redisClient, MUTEX_NAME)
}
async getLockedStreamIds() {
return (await this.redisClient.smembers(LOCKED_STREAM_IDS_REDIS_KEY)) || []
}
async addLockedStreamIds(streamIds : string[]) {
return this.redisClient.sadd(LOCKED_STREAM_IDS_REDIS_KEY, streamIds)
}
async removeLockedStreamIds(streamIds : string[]) {
return this.redisClient.srem(LOCKED_STREAM_IDS_REDIS_KEY, streamIds)
}
async deleteLockedStreamIds() {
return this.redisClient.del(LOCKED_STREAM_IDS_REDIS_KEY)
}
async getNotFullStreamIds() {
return (await this.redisClient.smembers(NOT_FULL_STREAM_IDS_REDIS_KEY)) || []
}
async addNotFullStreamIds(streamIds : string[]) {
return this.redisClient.sadd(NOT_FULL_STREAM_IDS_REDIS_KEY, streamIds)
}
async removeNotFullStreamIds(streamIds : string[]) {
return this.redisClient.srem(NOT_FULL_STREAM_IDS_REDIS_KEY, streamIds)
}
async deleteNotFullStreamIds() {
return this.redisClient.del(NOT_FULL_STREAM_IDS_REDIS_KEY)
}
}
当我尝试导入它时,出现以下错误:
TSError: ⨯ Unable to compile TypeScript:
src/lib/cache.ts:10:14 - error TS2339: Property 'redisClient' does not exist on type 'RedisCache'.
10 this.redisClient = new Redis(redisConfig);
~~~~~~~~~~~
src/lib/cache.ts:11:14 - error TS2339: Property 'mutex' does not exist on type 'RedisCache'.
11 this.mutex = new redis_semaphore_1.Mutex(this.redisClient, MUTEX_NAME);
~~~~~
src/lib/cache.ts:11:55 - error TS2339: Property 'redisClient' does not exist on type 'RedisCache'.
11 this.mutex = new redis_semaphore_1.Mutex(this.redisClient, MUTEX_NAME);
~~~~~~~~~~~
src/lib/cache.ts:14:28 - error TS2339: Property 'redisClient' does not exist on type 'RedisCache'.
14 return (await this.redisClient.smembers(LOCKED_STREAM_IDS_REDIS_KEY)) || [];
~~~~~~~~~~~
src/lib/cache.ts:17:21 - error TS2339: Property 'redisClient' does not exist on type 'RedisCache'.
17 return this.redisClient.sadd(LOCKED_STREAM_IDS_REDIS_KEY, streamIds);
~~~~~~~~~~~
src/lib/cache.ts:20:21 - error TS2339: Property 'redisClient' does not exist on type 'RedisCache'.
20 return this.redisClient.srem(LOCKED_STREAM_IDS_REDIS_KEY, streamIds);
~~~~~~~~~~~
src/lib/cache.ts:23:21 - error TS2339: Property 'redisClient' does not exist on type 'RedisCache'.
23 return this.redisClient.del(LOCKED_STREAM_IDS_REDIS_KEY);
~~~~~~~~~~~
src/lib/cache.ts:26:28 - error TS2339: Property 'redisClient' does not exist on type 'RedisCache'.
26 return (await this.redisClient.smembers(NOT_FULL_STREAM_IDS_REDIS_KEY)) || [];
~~~~~~~~~~~
src/lib/cache.ts:29:21 - error TS2339: Property 'redisClient' does not exist on type 'RedisCache'.
29 return this.redisClient.sadd(NOT_FULL_STREAM_IDS_REDIS_KEY, streamIds);
~~~~~~~~~~~
src/lib/cache.ts:32:21 - error TS2339: Property 'redisClient' does not exist on type 'RedisCache'.
32 return this.redisClient.srem(NOT_FULL_STREAM_IDS_REDIS_KEY, streamIds);
~~~~~~~~~~~
src/lib/cache.ts:35:21 - error TS2339: Property 'redisClient' does not exist on type 'RedisCache'.
35 return this.redisClient.del(NOT_FULL_STREAM_IDS_REDIS_KEY);
~~~~~~~~~~~
这非常令人困惑,因为RedisCache类中显然存在redisClient属性。 我已经尝试了所有方法:注释库,逐行注释,更改tsconfig中的设置,没有任何帮助。感谢您的提前帮助:^)