1
1
import { CacheHandler } from '@neshca/cache-handler' ;
2
2
import createLruHandler from '@neshca/cache-handler/local-lru' ;
3
3
import createRedisHandler from '@neshca/cache-handler/redis-strings' ;
4
- import { createClient } from 'redis ' ;
4
+ import { createClient } from 'valkey ' ;
5
5
import winston , { format } from 'winston' ;
6
6
7
7
const logger = winston . createLogger ( {
@@ -16,39 +16,39 @@ CacheHandler.onCreation(async () => {
16
16
17
17
try {
18
18
client = createClient ( {
19
- url : process . env . REDIS_URI_STILLINGSOK ?? 'redis://localhost:6379' ,
20
- username : process . env . REDIS_USERNAME_STILLINGSOK ?? '' ,
21
- password : process . env . REDIS_PASSWORD_STILLINGSOK ?? '' ,
19
+ url : process . env . VALKEY_URI_STILLINGSOK ?? 'redis://localhost:6379' ,
20
+ username : process . env . VALKEY_USERNAME_STILLINGSOK ?? '' ,
21
+ password : process . env . VALKEY_PASSWORD_STILLINGSOK ?? '' ,
22
22
disableOfflineQueue : true ,
23
23
pingInterval : 1000 * 60 , // 30 seconds
24
24
} ) ;
25
25
26
- client . on ( 'error' , err => logger . error ( 'Redis Client Error' , err ) ) ;
26
+ client . on ( 'error' , err => logger . error ( 'Valkey Client Error' , err ) ) ;
27
27
} catch ( error ) {
28
- logger . error ( 'Failed to create Redis client:' , error ) ;
28
+ logger . error ( 'Failed to create Valkey client:' , error ) ;
29
29
}
30
30
31
- if ( process . env . REDIS_AVAILABLE && client ) {
31
+ if ( process . env . VALKEY_AVAILABLE && client ) {
32
32
try {
33
- logger . info ( 'Connecting Redis client...' ) ;
33
+ logger . info ( 'Connecting Valkey client...' ) ;
34
34
35
35
// Wait for the client to connect.
36
36
// Caveat: This will block the server from starting until the client is connected.
37
37
// And there is no timeout. Make your own timeout if needed.
38
38
await client . connect ( ) ;
39
- logger . info ( 'Redis client connected.' ) ;
39
+ logger . info ( 'Valkey client connected.' ) ;
40
40
} catch ( error ) {
41
- logger . warn ( 'Failed to connect Redis client:' , error ) ;
41
+ logger . warn ( 'Failed to connect Valkey client:' , error ) ;
42
42
43
- logger . warn ( 'Disconnecting the Redis client...' ) ;
43
+ logger . warn ( 'Disconnecting the Valkey client...' ) ;
44
44
// Try to disconnect the client to stop it from reconnecting.
45
45
client
46
46
. disconnect ( )
47
47
. then ( ( ) => {
48
- logger . info ( 'Redis client disconnected.' ) ;
48
+ logger . info ( 'Valkey client disconnected.' ) ;
49
49
} )
50
50
. catch ( ( ) => {
51
- logger . warn ( 'Failed to quit the Redis client after failing to connect.' ) ;
51
+ logger . warn ( 'Failed to quit the Valkey client after failing to connect.' ) ;
52
52
} ) ;
53
53
}
54
54
}
@@ -63,10 +63,10 @@ CacheHandler.onCreation(async () => {
63
63
timeoutMs : 1000 ,
64
64
} ) ;
65
65
} else {
66
- // Fallback to LRU handler if Redis client is not available.
66
+ // Fallback to LRU handler if Valkey client is not available.
67
67
// The application will still work, but the cache will be in memory only and not shared.
68
68
handler = createLruHandler ( ) ;
69
- logger . warn ( 'Falling back to LRU handler because Redis client is not available.' ) ;
69
+ logger . warn ( 'Falling back to LRU handler because Valkey client is not available.' ) ;
70
70
}
71
71
72
72
return {
0 commit comments