Невозможно запустить команды Redis с хоста Windows на сервере Redis, работающем в контейнере Docker на моем WSL2.C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Невозможно запустить команды Redis с хоста Windows на сервере Redis, работающем в контейнере Docker на моем WSL2.

Сообщение Anonymous »

Я запускаю redis-stack в контейнере Docker на своем экземпляре WSL2:

Код: Выделить всё

mark@L-R910LPKW:~$ docker ps
CONTAINER ID  IMAGE                               COMMAND         CREATED       STATUS           PORTS                                           NAMES
b6530cb6eecf  docker.io/redis/redis-stack:latest  /entrypoint.sh  17 hours ago  Up 17 hours ago  0.0.0.0:6379->6379/tcp, 0.0.0.0:8001->8001/tcp  redis-stack
mark@L-R910LPKW:~$
На самом хосте Windows я могу перейти по адресу http://localhost:8001 и получить доступ к графическому интерфейсу Redis Insights, работающему в том же контейнере. Он отлично отображает данные.
В WSL2 я без проблем могу подключиться к серверу Redis. У меня нет клиента redis-cli (кроме того, который доступен в контейнере), поэтому я буду использовать команду nc для запуска команды Redis PING:

Код: Выделить всё

mark@L-R910LPKW:~$ nc localhost 6379
ping
+PONG
^C
mark@L-R910LPKW:~$
На хосте Windows у меня нет ни клиента Redis, ни инструмента NC. Но у меня есть git-bash и это работает:

Код: Выделить всё

/c/dayforce/aida$ exec 3/dev/tcp/localhost/6379

/c/dayforce/aida$ echo -e "PING\r\n" >&3

/c/dayforce/aida$ cat  Encoding.UTF8;
}

public class LocalRedis
{
private readonly IConnectionMultiplexer sut;

public LocalRedis(ITestOutputHelper testOutputHelper)
{
if (Environment.GetEnvironmentVariable("TF_BUILD") == null)
{
sut = ConnectionMultiplexer.Connect("localhost,abortConnect=false", new XUnitTextWriter(testOutputHelper));
}
}

[SkippableFact]
public void Ping()
{
Skip.If(sut == null, $"{GetType().Name} tests can only run locally.");

var db = sut.GetDatabase();
db.Ping();
}
}
И эта штука терпит неудачу:

Код: Выделить всё

C:\xyz\aida\aida-api\tests\AidaApi.Tests\bin\Debug\net8.0> vstest.console.exe AidaApi.Tests.dll /Tests:Ping
VSTest version 17.11.1 (x64)

Starting test discovery, please wait...
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.1+ce9211e970 (64-bit .NET 8.0.8)
[xUnit.net 00:00:00.09]   Discovering: AidaApi.Tests
[xUnit.net 00:00:00.16]   Discovered:  AidaApi.Tests
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.1+ce9211e970 (64-bit .NET 8.0.8)
[xUnit.net 00:00:00.08]   Starting:    AidaApi.Tests
[xUnit.net 00:00:20.20]     AidaApi.Tests.Connectors.LocalRedis.Ping [FAIL]
[xUnit.net 00:00:20.21]       StackExchange.Redis.RedisConnectionException : The message timed out in the backlog attempting to send because no connection became available (5000ms) - Last Connection Exception: It was not possible to connect to the redis server(s). ConnectTimeout, command=PING, timeout: 5000, inst: 0, qu: 0, qs: 0, aw: False, bw: SpinningDown, rs: NotStarted, ws: Idle, in: 0, last-in: 0, cur-in: 0, sync-ops: 1, async-ops: 0, serverEndpoint: localhost:6379, conn-sec: n/a, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: L-R910LPKW(SE.Redis-v2.8.0.27420), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=2,Free=32765,Min=12,Max=32767), POOL: (Threads=10,QueuedItems=0,CompletedItems=80,Timers=6), v: 2.8.0.27420 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)
[xUnit.net 00:00:20.21]       ---- StackExchange.Redis.RedisConnectionException : It was not possible to connect to the redis server(s).  ConnectTimeout
[xUnit.net 00:00:20.21]       Stack Trace:
[xUnit.net 00:00:20.21]         /_/src/StackExchange.Redis/ConnectionMultiplexer.cs(2105,0): at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server, T defaultValue)
[xUnit.net 00:00:20.21]         /_/src/StackExchange.Redis/RedisBase.cs(62,0): at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server, T defaultValue)
[xUnit.net 00:00:20.21]         /_/src/StackExchange.Redis/RedisBase.cs(24,0): at StackExchange.Redis.RedisBase.Ping(CommandFlags flags)
[xUnit.net 00:00:20.21]         C:\xyz\aida\aida-api\tests\AidaApi.Tests\Connectors\LocalRedis.cs(38,0): at AidaApi.Tests.Connectors.LocalRedis.Ping()
[xUnit.net 00:00:20.21]            at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
[xUnit.net 00:00:20.21]            at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
[xUnit.net 00:00:20.21]         ----- Inner Stack Trace -----
[xUnit.net 00:00:20.21]
[xUnit.net 00:00:20.21]       Output:
[xUnit.net 00:00:20.21]         Connecting (sync) on .NET 8.0.8 (StackExchange.Redis: v2.8.0.27420)
[xUnit.net 00:00:20.21]         localhost,abortConnect=False
[xUnit.net 00:00:20.21]         localhost:6379/Interactive: Connecting...
[xUnit.net 00:00:20.21]         localhost:6379: BeginConnectAsync
[xUnit.net 00:00:20.21]         1 unique nodes specified (with tiebreaker)
[xUnit.net 00:00:20.21]         localhost:6379: OnConnectedAsync init (State=Connecting)
[xUnit.net 00:00:20.21]         Allowing 1 endpoint(s) 00:00:05 to respond...
[xUnit.net 00:00:20.21]         Awaiting 1 available task completion(s) for 5000ms, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=2,Free=32765,Min=12,Max=32767), POOL: (Threads=3,QueuedItems=0,CompletedItems=4,Timers=3)
[xUnit.net 00:00:20.21]         Not all available tasks completed cleanly (from ReconfigureAsync#1499, timeout 5000ms), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=5,Free=32762,Min=12,Max=32767), POOL: (Threads=7,QueuedItems=0,CompletedItems=13,Timers=1)
[xUnit.net 00:00:20.21]         localhost:6379: OnConnectedAsync completed (Disconnected)
[xUnit.net 00:00:20.21]           Server[0] (localhost:6379) Status: WaitingForActivation (inst: 0, qs: 0, in: 0, qu: 0, aw: False, in-pipe: -1, out-pipe: -1, bw: Inactive, rs: NotStarted.  ws: Initializing)
[xUnit.net 00:00:20.21]         Endpoint summary:
[xUnit.net 00:00:20.21]           localhost:6379: Endpoint is (Interactive: Connecting, Subscription: Connecting)
[xUnit.net 00:00:20.21]         Task summary:
[xUnit.net 00:00:20.21]           localhost:6379: Returned, but incorrectly
[xUnit.net 00:00:20.21]         Election summary:
[xUnit.net 00:00:20.21]           Election: localhost:6379 had no tiebreaker set
[xUnit.net 00:00:20.21]           Election: No primaries detected
[xUnit.net 00:00:20.21]         Endpoint Summary:
[xUnit.net 00:00:20.21]           localhost:6379: Standalone v3.0.0, primary; keep-alive: 00:01:00; int: Connecting; sub: Connecting; not in use: DidNotRespond
[xUnit.net 00:00:20.21]           localhost:6379: int ops=0, qu=0, qs=0, qc=0, wr=0, socks=2; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=2
[xUnit.net 00:00:20.21]         Connection failed: localhost:6379 (Interactive, UnableToConnect): UnableToConnect on localhost:6379/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 5s ago, last-write: 5s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 5s ago, v: 2.8.0.27420
[xUnit.net 00:00:20.21]         Connection failed: localhost:6379 (Subscription, UnableToConnect): UnableToConnect on localhost:6379/Subscription, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 5s ago, last-write: 5s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 5s ago, v: 2.8.0.27420
[xUnit.net 00:00:20.21]           localhost:6379: Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s)
[xUnit.net 00:00:20.21]         Sync timeouts: 0; async timeouts: 0; fire and forget: 0; last heartbeat: -1s ago
[xUnit.net 00:00:20.21]         Resetting failing connections to retry...
[xUnit.net 00:00:20.21]           Retrying - attempts left: 2...
[xUnit.net 00:00:20.21]         1 unique nodes specified (with tiebreaker)
[xUnit.net 00:00:20.21]         localhost:6379: OnConnectedAsync init (State=Connecting)
[xUnit.net 00:00:20.21]         Allowing 1 endpoint(s) 00:00:05 to respond...
[xUnit.net 00:00:20.21]         Awaiting 1 available task completion(s) for 5000ms, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=5,Free=32762,Min=12,Max=32767), POOL: (Threads=10,QueuedItems=0,CompletedItems=30,Timers=3)
[xUnit.net 00:00:20.21]         Not all available tasks completed cleanly (from ReconfigureAsync#1499, timeout 5000ms), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=3,Free=32764,Min=12,Max=32767), POOL: (Threads=10,QueuedItems=0,CompletedItems=40,Timers=1)
[xUnit.net 00:00:20.21]           Server[0] (localhost:6379) Status: WaitingForActivation (inst: 0, qs: 0, in: -1, qu: 0, aw: False, in-pipe: -1, out-pipe: -1, bw: Inactive, rs: NA.  ws: NA)
[xUnit.net 00:00:20.21]         Endpoint summary:
[xUnit.net 00:00:20.21]           localhost:6379: Endpoint is (Interactive: Disconnected, Subscription: Disconnected)
[xUnit.net 00:00:20.21]         Task summary:
[xUnit.net 00:00:20.21]           localhost:6379: Did not respond (Task.Status: WaitingForActivation)
[xUnit.net 00:00:20.21]         Election summary:
[xUnit.net 00:00:20.21]           Election: localhost:6379 had no tiebreaker set
[xUnit.net 00:00:20.21]           Election: No primaries detected
[xUnit.net 00:00:20.21]         Endpoint Summary:
[xUnit.net 00:00:20.21]           localhost:6379: Standalone v3.0.0, primary; keep-alive: 00:01:00; int: Disconnected; sub: Disconnected; not in use: DidNotRespond
[xUnit.net 00:00:20.21]           localhost:6379: int ops=0, qu=0, qs=0, qc=0, wr=0, socks=2; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=2
[xUnit.net 00:00:20.21]           localhost:6379: Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s)
[xUnit.net 00:00:20.21]         Sync timeouts: 0; async timeouts: 0; fire and forget: 0; last heartbeat: -1s ago
[xUnit.net 00:00:20.21]         Resetting failing connections to retry...
[xUnit.net 00:00:20.21]           Retrying - attempts left: 1...
[xUnit.net 00:00:20.21]         1 unique nodes specified (with tiebreaker)
[xUnit.net 00:00:20.21]         localhost:6379: OnConnectedAsync init (State=Connecting)
[xUnit.net 00:00:20.21]         Allowing 1 endpoint(s) 00:00:05 to respond...
[xUnit.net 00:00:20.21]         Awaiting 1 available task completion(s) for 5000ms, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=4,Free=32763,Min=12,Max=32767), POOL: (Threads=10,QueuedItems=0,CompletedItems=40,Timers=3)
[xUnit.net 00:00:20.21]         Not all available tasks completed cleanly (from ReconfigureAsync#1499, timeout 5000ms), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=7,Free=32760,Min=12,Max=32767), POOL: (Threads=10,QueuedItems=0,CompletedItems=49,Timers=1)
[xUnit.net 00:00:20.21]         localhost:6379: OnConnectedAsync completed (Disconnected)
[xUnit.net 00:00:20.21]         localhost:6379: OnConnectedAsync completed (Disconnected)
[xUnit.net 00:00:20.21]           Server[0] (localhost:6379) Status: WaitingForActivation (inst: 0, qs: 0, in: -1, qu: 0, aw: False, in-pipe: -1, out-pipe: -1, bw: Inactive, rs: NA. ws: NA)
[xUnit.net 00:00:20.21]         Endpoint summary:
[xUnit.net 00:00:20.21]           localhost:6379: Endpoint is (Interactive: Disconnected, Subscription: Disconnected)
[xUnit.net 00:00:20.21]         Task summary:
[xUnit.net 00:00:20.21]           localhost:6379: Returned, but incorrectly
[xUnit.net 00:00:20.21]         Election summary:
[xUnit.net 00:00:20.21]           Election: localhost:6379 had no tiebreaker set
[xUnit.net 00:00:20.21]           Election: No primaries detected
[xUnit.net 00:00:20.21]         Endpoint Summary:
[xUnit.net 00:00:20.21]           localhost:6379: Standalone v3.0.0, primary; keep-alive: 00:01:00; int: Disconnected; sub: Disconnected; not in use: DidNotRespond
[xUnit.net 00:00:20.21]           localhost:6379: int ops=0, qu=0, qs=0, qc=0, wr=0, socks=3; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=3
[xUnit.net 00:00:20.21]           localhost:6379: Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s)
[xUnit.net 00:00:20.21]         Sync timeouts: 0; async timeouts: 0; fire and forget: 0; last heartbeat: -1s ago
[xUnit.net 00:00:20.21]         Starting heartbeat...
[xUnit.net 00:00:20.21]         Total connect time: 15,051 ms
[xUnit.net 00:00:20.22]   Finished:    AidaApi.Tests
Failed AidaApi.Tests.Connectors.LocalRedis.Ping [20 s]
Error Message:
...

Test Run Failed.
Total tests: 1
Failed: 1
Total time: 20.6085 Seconds
C:\xyz\aida\aida-api\tests\AidaApi.Tests\bin\Debug\net8.0>
(По какой-то причине трассировка стека и захваченные выходные данные печатаются дважды — один раз с префиксом [xUnit.net 00:00:...], а затем без префикса, поэтому я для краткости заменил последнее многоточием)
Я новичок в Redis, и мне совершенно непонятно, что происходит. Кроме того, меня озадачил следующий вывод при запуске модульного теста:

Код: Выделить всё

localhost:6379: Standalone v3.0.0, ...
Интересно, что это значит, учитывая, что команда INFO сообщает версию сервера как 7.4.0.
Изменить 1
Я заменил localhost на 127.0.0.1, и всё заработало. Итак, теперь вопрос: в чем проблема с localhost в .NET, ведь в Git Bash он отлично работал.

Подробнее здесь: https://stackoverflow.com/questions/790 ... running-in
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»