@@ -85,6 +85,20 @@ class RedisService {
8585 }
8686 }
8787
88+ duplicate ( ) : RedisClientType {
89+ return this . client . duplicate ( ) ;
90+ }
91+
92+ async configSet ( params : string , value : string ) : Promise < void > {
93+ await this . ensureConnection ( ) ;
94+
95+ try {
96+ await this . client . configSet ( params , value ) ;
97+ } catch ( error ) {
98+ logger . error ( `Redis CONFIG SET ${ params } error:` , error ) ;
99+ }
100+ }
101+
88102 async set (
89103 key : string ,
90104 value : string ,
@@ -150,12 +164,13 @@ class RedisService {
150164 }
151165 }
152166
153- async lpush ( key : string , value : string ) : Promise < void > {
167+ async lpush ( key : string , value : string | string [ ] ) : Promise < number > {
154168 await this . ensureConnection ( ) ;
155169 try {
156- await this . client . lPush ( key , value ) ;
170+ return await this . client . lPush ( key , value ) ;
157171 } catch ( error ) {
158172 logger . error ( "Redis LPUSH error:" , error ) ;
173+ return 0 ;
159174 }
160175 }
161176
@@ -219,6 +234,57 @@ class RedisService {
219234 }
220235 }
221236
237+ async sAdd ( key : string , members : string | string [ ] ) : Promise < number > {
238+ await this . ensureConnection ( ) ;
239+ try {
240+ return await this . client . sAdd ( key , members ) ;
241+ } catch ( error ) {
242+ logger . error ( "Redis SADD error:" , error ) ;
243+ return 0 ;
244+ }
245+ }
246+
247+ async sRem ( key : string , members : string | string [ ] ) : Promise < number > {
248+ await this . ensureConnection ( ) ;
249+ try {
250+ return await this . client . sRem ( key , members ) ;
251+ } catch ( error ) {
252+ logger . error ( "Redis SREM error:" , error ) ;
253+ return 0 ;
254+ }
255+ }
256+
257+ async sCard ( key : string ) : Promise < number > {
258+ await this . ensureConnection ( ) ;
259+ try {
260+ return await this . client . sCard ( key ) ;
261+ } catch ( error ) {
262+ logger . error ( "Redis SCARD error:" , error ) ;
263+ return 0 ;
264+ }
265+ }
266+
267+ async sPop ( key : string , count ?: number ) : Promise < string [ ] | null > {
268+ await this . ensureConnection ( ) ;
269+ try {
270+ if ( count && count > 1 ) {
271+ const results : string [ ] = [ ] ;
272+ for ( let i = 0 ; i < count ; i ++ ) {
273+ const item = await this . client . sPop ( key ) ;
274+ if ( ! item ) break ;
275+ results . push ( item ) ;
276+ }
277+ return results . length > 0 ? results : null ;
278+ }
279+
280+ const result = await this . client . sPop ( key ) ;
281+ return result ? [ result ] : null ;
282+ } catch ( error ) {
283+ logger . error ( "Redis SPOP error:" , error ) ;
284+ return null ;
285+ }
286+ }
287+
222288 async zadd ( key : string , score : number , member : string ) : Promise < void > {
223289 await this . ensureConnection ( ) ;
224290 try {
@@ -282,6 +348,27 @@ class RedisService {
282348 }
283349 }
284350
351+ async pSubscribe (
352+ pattern : string ,
353+ callback : ( message : string , channel : string ) => void
354+ ) : Promise < void > {
355+ await this . ensureConnection ( ) ;
356+ try {
357+ await this . client . pSubscribe ( pattern , callback ) ;
358+ } catch ( error ) {
359+ logger . error ( "Redis PSUBSCRIBE error:" , error ) ;
360+ }
361+ }
362+
363+ async pUnsubscribe ( pattern : string ) : Promise < void > {
364+ await this . ensureConnection ( ) ;
365+ try {
366+ await this . client . pUnsubscribe ( pattern ) ;
367+ } catch ( error ) {
368+ logger . error ( "Redis PUNSUBSCRIBE error:" , error ) ;
369+ }
370+ }
371+
285372 async setJSON ( key : string , value : any , ttl ?: number ) : Promise < void > {
286373 const jsonValue = JSON . stringify ( value ) ;
287374 if ( ttl ) {
0 commit comments