redisClient.connect is not a function. createClient gives me different object in terminal

See original GitHub issue

redisClient.connect is not a function.

  • createClient function gives me RedisClient instance when I use it in my application.
  • createClient function gives me Commander instance when I use it in the terminal.

Environment:

  • Node.js Version:v12.22.9 - npm 6.14.15
  • Redis Server Version: 3.0.6
  • Node Redis Version: `-- redis@4.0.2
  • Platform: Ubuntu 20.04.3
  • Docker image: node:12-alpine

Node from terminal


/home/Backend $ node
Welcome to Node.js v12.22.9.
Type ".help" for more information.
> redis = require('redis');
{
  createClient: [Function: createClient],
  createCluster: [Function: createCluster],
  commandOptions: [Getter],
  defineScript: [Getter],
  AbortError: [Getter],
  WatchError: [Getter],
  ConnectionTimeoutError: [Getter],
  ClientClosedError: [Getter],
  DisconnectsClientError: [Getter],
  SocketClosedUnexpectedlyError: [Getter],
  AuthError: [Getter],
  RootNodesUnavailableError: [Getter],
  ReconnectStrategyError: [Getter],
  SchemaFieldTypes: [Getter],
  SchemaTextFieldPhonetics: [Getter],
  AggregateSteps: [Getter],
  AggregateGroupByReducers: [Getter]
}
> redisClient = redis.createClient()
Commander {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  commandOptions: [Function: commandOptions],
  select: [AsyncFunction: SELECT],
  subscribe: [Function: SUBSCRIBE],
  pSubscribe: [Function: PSUBSCRIBE],
  unsubscribe: [Function: UNSUBSCRIBE],
  pUnsubscribe: [Function: PUNSUBSCRIBE],
  quit: [Function: QUIT],
  bf: { self: [Circular] },
  cms: { self: [Circular] },
  cf: { self: [Circular] },
  topK: { self: [Circular] },
  json: { self: [Circular] },
  ft: { self: [Circular] },
  ts: { self: [Circular] },
  [Symbol(kCapture)]: false
}
> redisClient.connect
[AsyncFunction: connect]
> 






Application Code

// this is my code on the server..
const redisClient = redis.createClient({
    url: `redis://${REDIS_HOST}:${REDIS_PORT}`
})
console.log('redisClient', redisClient);
console.log('connect function', redisClient.connect);

Application Output

redisClient RedisClient {
  _events: [Object: null prototype] { newListener: [Function] },
  _eventsCount: 1,
  _maxListeners: undefined,
  address: 'redis:6379',
  connection_options: { port: 6379, host: 'redis', family: 4 },
  connection_id: 0,
  connected: false,
  ready: false,
  should_buffer: false,
  max_attempts: 0,
  command_queue: Deque { _capacity: 16, _length: 0, _front: 0 },
  offline_queue: Deque { _capacity: 16, _length: 0, _front: 0 },
  pipeline_queue: Deque { _capacity: 16, _length: 0, _front: 0 },
  connect_timeout: 3600000,
  enable_offline_queue: true,
  retry_max_delay: null,
  retry_timer: null,
  retry_totaltime: 0,
  retry_delay: 200,
  retry_backoff: 1.7,
  attempts: 1,
  pub_sub_mode: 0,
  subscription_set: {},
  monitoring: false,
  message_buffers: false,
  closing: false,
  server_info: {},
  auth_pass: undefined,
  selected_db: undefined,
  old_state: null,
  fire_strings: true,
  pipeline: false,
  sub_commands_left: 0,
  times_connected: 0,
  buffers: false,
  options: {
    port: '6379',
    host: 'redis',
    url: 'redis://redis:6379',
    socket_nodelay: true,
    socket_keepalive: true,
    return_buffers: false,
    detect_buffers: false
  },
  reply: 'ON',
  reply_parser: JavascriptRedisParser {
    optionReturnBuffers: false,
    optionStringNumbers: false,
    returnError: [Function: returnError],
    returnFatalError: [Function: returnFatalError],
    returnReply: [Function: returnReply],
    name: 'javascript',
    offset: 0,
    buffer: null,
    bigStrSize: 0,
    bigOffset: 0,
    totalChunkSize: 0,
    bufferCache: [],
    arrayCache: [],
    arrayPos: []
  },
  stream: Socket {
    connecting: true,
    _hadError: false,
    _parent: null,
    _host: 'redis',
    _readableState: ReadableState {
      objectMode: false,
      highWaterMark: 16384,
      buffer: BufferList { head: null, tail: null, length: 0 },
      length: 0,
      pipes: null,
      pipesCount: 0,
      flowing: true,
      ended: false,
      endEmitted: false,
      reading: false,
      sync: true,
      needReadable: false,
      emittedReadable: false,
      readableListening: false,
      resumeScheduled: true,
      emitClose: false,
      autoDestroy: false,
      destroyed: false,
      defaultEncoding: 'utf8',
      awaitDrainWriters: null,
      multiAwaitDrain: false,
      readingMore: false,
      decoder: null,
      encoding: null,
      [Symbol(kPaused)]: false
    },
    readable: false,
    _events: [Object: null prototype] {
      end: [Array],
      connect: [Function],
      data: [Function],
      error: [Function],
      clientError: [Function],
      close: [Function],
      drain: [Function]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    _writableState: WritableState {
      objectMode: false,
      highWaterMark: 16384,
      finalCalled: false,
      needDrain: false,
      ending: false,
      ended: false,
      finished: false,
      destroyed: false,
      decodeStrings: false,
      defaultEncoding: 'utf8',
      length: 0,
      writing: false,
      corked: 0,
      sync: true,
      bufferProcessing: false,
      onwrite: [Function: bound onwrite],
      writecb: null,
      writelen: 0,
      afterWriteTickInfo: null,
      bufferedRequest: null,
      lastBufferedRequest: null,
      pendingcb: 0,
      prefinished: false,
      errorEmitted: false,
      emitClose: false,
      autoDestroy: false,
      bufferedRequestCount: 0,
      corkedRequestsFree: [Object]
    },
    writable: true,
    allowHalfOpen: false,
    _sockname: null,
    _pendingData: null,
    _pendingEncoding: '',
    server: null,
    _server: null,
    [Symbol(asyncId)]: 28,
    [Symbol(kHandle)]: TCP {
      reading: false,
      onconnection: null,
      [Symbol(owner_symbol)]: [Circular]
    },
    [Symbol(kSetNoDelay)]: true,
    [Symbol(lastWriteQueueSize)]: 0,
    [Symbol(timeout)]: null,
    [Symbol(kBuffer)]: null,
    [Symbol(kBufferCb)]: null,
    [Symbol(kBufferGen)]: null,
    [Symbol(kCapture)]: false,
    [Symbol(kBytesRead)]: 0,
    [Symbol(kBytesWritten)]: 0
  },
  [Symbol(kCapture)]: false
}
connect function undefined



Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

6reactions
leibalecommented, Jan 16, 2022

Looks like you have 2 versions of node-redis installed, try to

console.log(`node-redis version is ${require('redis/package.json').version}`);

in both the app and the terminal

0reactions
CaCaBlockercommented, Aug 7, 2022

@CaCaBlocker IIRC, v3 had no connect function (you need to wait for the connect event if you want to make sure the client is connected). https://github.com/redis/node-redis/tree/v3.1.2

Thanks. I convert the version successfully. 😊

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Nodejs Redis createClient() function - Stack Overflow
Now, first you have to build a connection between the node app and redis-server so that they can communicate between then.
Read more >
redis.createClient JavaScript and Node.js code examples
connect (callback) { this.client = redis.createClient(); this.client.on('error', (err) => { console.error("This demo requires Redis, a simple message broker.
Read more >
How to establish connection between Node.js ans Redis
The Redis module's createclient() method creates a Redis object. const redis = require('redis') const redisClient = redis.createClient().
Read more >
Using Redis with Node.js - SitePoint
All the Redis commands are exposed as different functions on the client object. To store a simple string, use the following syntax:
Read more >
Session handling in Express Using Redis | Code for geek
Express session with Redis. To add support of Redis you have to use Redis client and connect-redis. Create express-session and pass it to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found