Redis Connection Refused Mac

  

Connection refused. 2017-09-08T11:43+00:00 herokuworker.1: State changed from up to crashed 2017-09-08T11:33+00:00 herokuworker.1: Process exited with status 1 2017-09-08T11:55:10+00:00 appheroku-redis: source=REDIS sample#active-connections=2 sample#load-avg-1m=0.315 sample#load-avg-5m=0.21 sample#load-avg-15m=0.16. Please help me to fix this. Tony@kali:$ redis-cli Could not connect to Redis at 127.0.0.1:6379: Connection refused Could not connect to Redis a. About; Products. On mac 'src/redis-cli & src/redis-server' works for me.

Redis is a very popular data store used across all kinds of web apps it’s supported natively by Mac and Linux operating systems. Heck, you can even use Docker to run Redis.

The purpose of this guide is to setup Redis so we can use in our Python applications including Django, Flask, Fastapi, Celery, and pure python apps.

Are you a windows user? Check out this redis install guide

Do you need to use Redis on Docker? The windows install guide shows you how.

3.1. Install Redis on macOS¶

3.1.1. Install Homebrew¶

3.1.2. Install redis¶

Every once and a while run brewupgraderedis

3.1.3. Start / Stop Redis¶

Starting redis this way turns redis into a background service. You can easily stop redis with:

3.1.4. Verify redis is running:¶

What result do you see?

  • PONG – great, redis is working and ready.

  • CouldnotconnecttoRedisat127.0.0.1:6379:Connectionrefused – this means that: (1) you did not install redis correctly or (2) redis is not running.

3.2. Install Redis on Linux (using Ubuntu)¶

Below was adapted from the production-ready guide in our series Hello Linux

3.2.1. Update System¶

3.2.2. Install redis-server

3.2.3. Update configuration¶

Update supervised to the following:

Save and exit nano.

Restart running service:

3.2.4. Verify installation:¶

What result do you see?

  • PONG – great, redis is working and ready.

  • CouldnotconnecttoRedisat127.0.0.1:6379:Connectionrefused – this means that: (1) you did not install redis correctly, (2) redis is not running, or (3) the system service did not start (check with sudosystemctlstatusredis)

3.3. Install on Windows 10 using Docker¶

Naturally, you need to install docker desktop on your windows 10. There’s a huge caveat that might push you towards using Memurai:

Docker requires you to have Windows 10 professional

Windows 10 professional allows for the OS virtualization that is just not provided in Windows 10 home.

  • Are you new to docker? Check out this basic intro

3.3.1. Verify Docker¶

Open PowerShell and run:

3.3.2. Create a project directory¶

3.3.3. Update (or create) a Dockerfile

You don’t have to build the redis image yourself but I prefer to so I can make changes easily and it’s already prepared for it.

3.3.4. Build our docker image:¶

Personally, I like adding commands like dockerbuild-t'cfe-redis'. to a build.ps1 file so I can just call ./build.ps1 if I ever want to build it again in the future.

3.3.5. Run our docker image:¶

A couple things to note:

-it--rm is so this docker container only runs when we want it to and the container will be removed after we’re done running it.

-p6379:6379 is exposing the port 6379 on our local system AND in our docker container.

cfe-redis is merely the tag name of the image we created in the build process.

Just like with build.ps1, make a run.ps1 file containing dockerrun-it--rm-p6379:6379'cfe-redis' as a shortcut to running this container.

3.3.6. Verify Docker connection¶

On Linux and Mac, you can just run redis-cliping but, since we’re using docker, we don’t have the redis-cli command available on our system.

We need another way to test. Since I use redis in my Python projects, I’ll create a simple python program to ensure our non-container items can connect to redis.

I already have Python 3.8 installed. If you don’t, check out this guide.

3.3.6.1. Create virtual environment¶

You can use pipenv as well. I’m just keeping things simple by using the built-in virtual environment manager

3.3.6.2. Activate virtual environment¶

3.3.6.3. Run pipinstallredis

This command does not install the redis server; it just installs a redis connector that we can use in python.

3.3.6.4. Create ping_redis.py

Notice the port=6379 I used? This is the default redis port and it matches to what I exposed above.

3.3.6.5. Run ping_redis.py

What result do you have?

  • Trueb'bar' – this means redis is running correctly

  • Noconnectioncouldbemadebecausethetargetmachineactivelyrefusedit. – this means your version of redis is either (1) not running or (2) running incorrectly or (3) you got the port number wrong.

3.3.7. Future running¶

Now, whenever you need to use redis in your projects. Just run:

Anywhere on your system.

3.4. Install Redis on Windows using Memurai.com¶

I haven’t used memurai much myself but it seems promising. Let’s see

3.4.2. Run downloaded installer¶

3.4.3. Agree to all defaults except port.¶

For the port, I’ll use 6380.

Mac

I’m leaving 6379 open. It’s the default redis port and I’m not 100% convinced I’ll use memurai in the future. I’m positive I’ll use Docker and so I’ll leave 6379 open for docker versions of redis like above.

3.4.4. Verify in Python – Create a virtual environment.¶

memurai should be running by default after you installed it so we need to verify.

Refused

Assuming you did not do the docker portion above, let’s create a new virtual environment to test redis is running via memurai. Open up PowerShell and run:

I already have Python 3.8 installed. If you don’t, check out this guide.

3.4.4.1. Activate virtual environment¶

3.4.4.2. Run pipinstallredis

This command does not install the redis server; it just installs a redis connector that we can use in python.

3.4.4.3. Create ping_redis.py

Notice the port=6380 I used? This is the redis port I used during the memurai installation.

Refused

3.4.4.4. Run ping_redis.py

What result do you have?

  • Trueb'bar' – this means redis is running correctly

  • Noconnectioncouldbemadebecausethetargetmachineactivelyrefusedit. – this means your version of redis is either (1) not running or (2) running incorrectly or (3) you got the port number wrong.

3.4.4.5. Future running¶

If you installed the defaults, memurai should start with your system startup just remember which port (6380) you used for the memurai redis.

I probably spend more time than most in redis-cli, because I find it invaluable when I’m writing software or getting to know a new module. If I didn’t have redis-cli, understanding Redis’ data structures and testing connections would be far more complicated, and I probably would’ve stopped using Redis long ago.

Redis-cli by itself isn’t that complicated – it’s a REPL (read–eval–print loop) that speaks to the Redis server. However, getting this jewel of a tool is not straightforward for many. The source for redis-cli is included in the Redis github repository and is automatically compiled when you build Redis from source. But what happens if you can’t (or don’t want to) build Redis from source? It means you also don’t have redis-cli and building an entire database from source just to get access to the command-line interface (CLI) utility is overkill and sometimes not even an option.

In this post, I’ll share how to get redis-cli without installing or having to make a full Redis server, but first let’s look at a couple scenarios.

Problem: Can’t built Redis from source

For those of us on Linux or macOS, building Redis from source involves having the relevant compilers and tools on your system and running make, which produces both the CLI and the Redis server. For most developers on these platforms, that’s not a huge burden.

However, if you’re not on a unix-like system, things get complicated quickly. For various reasons, you can’t just compile Redis on Windows. Microsoft once supported a fork of Redis that ran directly on Windows-based machines, but it’s no longer maintained. That means that, on Windows, you can’t get a current version of redis-cli. While it’s possible to use the Windows Subsystem for Linux that can run Redis, this has its own challenges, such as file system limitations and just generally not feeling native or appropriate for the system. In addition, there are many developers who have development machines locked down in fun and creative ways to explicitly block this type of operation.

Finally, you might be in a situation where you’re on a low-spec server and you just need to do some quick checks in Redis – getting the dependencies and building the software may not be possible in these constrained environments.

Problem: Don’t want to build Redis from source

There are many situations where you may be building software that uses Redis, but you’ll never personally manage or administer even a localhost process of Redis. Imagine if you’re using Redis Enterprise Cloud – you can have a Redis instance in seconds, but if you want to do anything with it you need to have CLI, which requires building the whole package from source. Or perhaps you’re at a large organization that is running a self-managed Redis Enterprise Software cluster. Here too, you may not have an actual need to build the Redis server on your development machine, since you just want to connect up remotely.

Finally, you might want to get up and running quickly. Pulling down the entire Redis C project (and all the tools needed to build that) might not be efficient for your workflow.

If you fall in one of the above scenarios, read on.

Invoking Atwood’s Law

In 2007, Jeff Atwood wrote, rather disparagingly:

“Any application that can be written in JavaScript will eventually be written in JavaScript.”

Refused

Bringing this to Redis, Lu Jiajing started a small project (less than 250 lines of JavaScript!) in 2015 to reimplement the overall operation of redis-cli in Node.js. Since then, it’s gotten closer to mimicking the Antirez-provided redis-cli. While not perfect (yet), it provides the bulk of the functionalities that you’d need on a day-to-day basis.

You may ask, why bother with this if you still have to install Node.js first? Well, first off, Node.js provides a much wider range of installation options than Redis. You can get it as a GUI msi for Windows or a pkg for macOS, as well as plain old compressed binaries for Windows, macOS or Linux, and you can also install Node.js via a package manager on many platforms.

Connection

Installing and running Node.js redis-cli

Once you’ve installed Node.js and npm, it’s a simple one-liner to get and install the Node.js version of redis-cli:

npm install -g redis-cli

Then you can run it with the command:

rdcli -h your.redis.host -a yourredispassword -p 11111

(using your relevant connection information).

Alternately, if you don’t like global installs, you can clone the repository and install the dependencies:

git clonehttps://github.com/lujiajing1126/redis-cli

cd redis-cli

npm install

Then you can run it from this directory by invoking the index.js file directly with the command line arguments:

node index.js -h your.redis.host -a yourredispassword -p 11111

(using your relevant connection information).

Redis-cli without building Redis

There you have it. You can get redis-cli up and running on your development machine quickly and easily with Node.js redis-cli written by Lu Jiajing. Instead of building the whole Redis project with C, you can just grab Node.js (even better if you already have it installed, and you probably do, let’s be honest), install this small module and start hacking away in Redis.

Bonus

One cool little use of this module is to make it a part of devDependencies in your package.json on a Node.js project. This way, you can effectively “pack-in” redis-cli with your project, making sure everyone on your team has the tool. To do this, install it as a development dependency:

npm install –save-dev redis-cli

Then in your package.json, add the following line to the beginning of the scripts object:

Redis Connection Refused Mac Download

“rediscli”: “node ./node_modules/redis-cli/index.js”,

Now, anyone who has your project can start redis-cli by running:

npm start rediscli -h your.redis.host -a yourredispassword -p 11111

(using your relevant connection information).

Docker Redis Connection Refused

You can even hard code in arguments if need be, but never include your Redis password in your package.json file!