strapi-plugin-redis icon indicating copy to clipboard operation
strapi-plugin-redis copied to clipboard

Add Socket Support

Open hypnotoad08 opened this issue 1 year ago • 2 comments

Modification to configuration.js and example config/index.js Tested on my local strapi instance and will be deploying to my prod version.

hypnotoad08 avatar Mar 19 '23 16:03 hypnotoad08

FYI this still does not work for Redis instance where there is no TCP connection available. it's building the socket and connecting fine, however, it still attempts to do the default.

strapi:strapi-plugin-redis Building optional connection +0ms ioredis:redis status[localhost:6379]: wait -> connecting +0ms strapi:strapi-plugin-redis Built optional connection - socket +1ms strapi:strapi-plugin-redis Building default connection +0ms ioredis:redis status[127.0.0.1:6379]: wait -> connecting +0ms strapi:strapi-plugin-redis Built default connection - stand-alone +1ms ioredis:connection error: Error: connect ECONNREFUSED 127.0.0.1:6379 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 6379 } +0ms [ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) ioredis:redis status[127.0.0.1:6379]: connecting -> close +50ms ioredis:connection reconnect in 50ms +5ms ioredis:redis status[127.0.0.1:6379]: close -> reconnecting +1ms ioredis:connection error: Error: connect ECONNREFUSED 127.0.0.1:6379 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 6379 } +1ms [2023-03-22 09:48:46.728] debug: ⛔️ Server wasn't able to start properly. [2023-03-22 09:48:46.730] error: Could not initialize REST Cache provider "redis": connect ECONNREFUSED 127.0.0.1:6379 Error: Could not initialize REST Cache provider "redis": connect ECONNREFUSED 127.0.0.1:6379 at EventEmitter.onError (D:\GitHub\Somos-Art\somos-server\node_modules\strapi-provider-rest-cache-redis\lib\index.js:20:9) at Object.onceWrapper (node:events:628:26) at EventEmitter.emit (node:events:513:28) at EventEmitter.emit (node:domain:489:12) at EventEmitter.silentEmit (D:\GitHub\Somos-Art\somos-server\node_modules\ioredis\built\Redis.js:460:30) at Socket. (D:\GitHub\Somos-Art\somos-server\node_modules\ioredis\built\redis\event_handler.js:189:14) at Object.onceWrapper (node:events:628:26) at Socket.emit (node:events:525:35) at Socket.emit (node:domain:489:12) at emitErrorNT (node:internal/streams/destroy:151:8)

I don't have a default listed in my strapi plugin.

redis: { enabled: true, config: { settings: { debug: true, debugIORedis: true, }, connections: { optional: { socket: { socketPath: env('SOCKET_PATH') }, db: 0 } }, }, }, "rest-cache": { enabled: true, config: { provider: { name: "redis", options: { max: 32767, connection: "optional", }, }, strategy: { contentTypes: [ // list of Content-Types UID to cache { contentType: "api::artwork.artwork", hitpass: false }, { contentType: "api::category.category", hitpass: false } ] }, }, }, }

I believe the build connections need to be shortchanged when one is successful instead of just doing a final else and falling back on default. I will continue working on this pull requet.

hypnotoad08 avatar Mar 22 '23 14:03 hypnotoad08

Sounds good :)

The main point with my review was that localhost/port should be the only default configuration. You shouldn't need to add anything into the config at all (since that's just the default and any user configuration would be merged with it).

If you are using the socket though, you may need to delete the default keys before you create the Redis client.

ioredis can get really picky if you pass in keys that it doesn't expect or need.

derrickmehaffy avatar Mar 23 '23 04:03 derrickmehaffy