跳到主要內容

[Redis] StackExchange.Redis cannot connect to Redis Server running on Ubuntu 1710

Problem description:
i have a Redis server running on Ubuntu 17.10 which install on VM, and would like to write C# code by StackExchange.Redis. This makes my app have the ability to connect Redis servers.
However, after running the following C# code connecting existing Redis server, some exception happens and suggests that this code fails to connect to the assigned Redis server.
Source file
01 ConnectionMultiplexer myRedisConn = ConnectionMultiplexer.Connect("192.168.234.128:6379");



Root Cause:
BIND in /etc/redis/redis.conf is set 127.0.01 as a default setting.

Solution:
In this case, we installed Redis 4.0.1 on Ubuntu 17.10 desktop version (x86_64).
Step 1:
Modify, manually, BIND as 0.0.0.0
Notice: 0.0.0.0 means that any external IP can connect to this Redis Server. If this server is not open to external use, you should specify restricted internal IP.

Step 2:
Restart Redis server by following command
$ sudo /etc/init.d/redis-server restart


As the following figure shows, i can now successfully connect to Redis running on Ubuntu (installed on VM). The client package I used is StackExchange.Redis installed on Visual Studio 2017. Package StachExchange can be obtained by using NuGet package manager.



This article in Tradition Chinese

Redis brief introduction:
Redis is in-memory key-value database and has been widely applied as cache server to accelerate data access speed. Redis is an open source database project and implemented a distributed in-memory DB.
In addition to Linux versions, Redis are also provided in Microsoft Azure and Amazon AWS.
* Amazon AWS
https://aws.amazon.com/tw/elasticache/what-is-redis/
* Microsoft Azure
https://azure.microsoft.com/zh-tw/services/cache/

Reference:
1. Redis Wiki
https://zh.wikipedia.org/wiki/Redis
2. Redis official website
https://redis.io/
3.
https://serverfault.com/questions/248248/cannot-connect-to-redis-installed-on-virtualbox-running-ubuntu-from-windows-7
4.
https://stackoverflow.com/questions/6910378/how-can-i-stop-redis-server
張貼留言

這個網誌中的熱門文章

[遊記] 20160710 廈門 - 中山路步行街,鼓浪嶼

此次趁出差之便,於周末從廈門翔安區到島內搭船到鼓浪嶼來看看這素有海上花園之稱的地方


[遊記] 20160702 廈門 - 廈門大學、南普陀寺、SM城市廣場

工作這麼久還是第一次出差
問了別人周末要到哪邊,都先推先到廈門大學來看看