I am running Redis through Docker in Windows. When I send the request to localhost:6379 it gives the following error:
SocketException: The remote computer refused the network connection.\r\n (OS Error: The remote computer refused the network connection.\r\n, errno = 1225), address = localhost, port = 8233
I am using Docker Desktop and running the official redis.
Following is my code in the dart_frog backend located at routes/cache/redis:
final conn = RedisConnection();
Handler middleware(Handler handler) {
return (context) async {
Response response;
try {
final command = await conn.connect('localhost', 6379);
try {
await command.send_object(['AUTH', 'default', 'pass']);
response =
await handler.use(provider<Command>((_) => command)).call(context);
// in case of success return Response.json(body: {'success': '$success'})
} catch (e) {
response = Response.json(
body: {'success': false, 'message': e.toString()},
);
}
} catch (e) {
response = Response.json(
body: {'success': false, 'message': e.toString()},
);
}
return response;
};
}
Simply creating a container in Docker Desktop from the official redis may not work.
Short Answer:
I used the following command in Powershell for creating redis container in docker-
After running it once, a working redis container is created and can be run through Docker Desktop.
Detailed Answer:
Consider the following steps for proper installation of Docker for Windows:
Install Docker Desktop for Windows
Pull the Official Redis Image from Docker Hub using Powershell:
Create and Run the Redis Container:
--name my-redis-container: This flag assigns a name (in this case, "my-redis-container") to your Redis container for easy reference.
-p 6379:6379: This flag maps port 6379 on your host machine to port 6379 inside the container, allowing you to access Redis from your Windows environment.
-d: This flag runs the container in detached mode.
Verify the Container is Running:
Steps for accessing Redis using docker are mentioned below.
Stop and Remove the Container. This can also be done through Docker Desktop.
Steps for accessing Redis running on Docker using dart_frog:
Make a GET request from dart_frog using Command Prompt:
After running this command, you should expect to see an empty line as the result.
Make a POST request from dart_frog using Command Prompt:
Check your result using a GET request as mentioned in step 1. You expected result should be:
In case you want to use GET and POST requests using Powershell:
GET:
POST: