mayulu

mayulu

Hi,

The question I tried a lot and have got no idea.

After

{:ok, conn} = Redix.start_link(host: "127.0.0.1", port: 6379) 

conn is PID like pid<0.554.0>

Then I send some special command to redis server:

{:ok, OK} = Redix.start_link(conn, [...some special command...]) 

The special redis server may then further push a series responses to conn separately and constantly.

I want to use :

:gen_tcp.recv(socket, 0)

to receive data from redis server in process pid<0.554.0>

But conn is a PID (etc. TCP Client) not a socket, So how can I get socket from the PID.

Anyone can give me a glue?

Thanks

Showing Posts 1 to 2

idi527

idi527

:waving_hand:

Maybe there is a way to do it via redix? Either way, redix probably keeps the socket in it’s state, you can try a hack like :sys.get_state(redix_conn) to find out.

:gen_tcp.recv(socket, 0) might not work if the socket is started in active: true mode. Seems like it is started with active: :once. And is reset to that mode after each received packet. So you might try something like

%{socket: socket} = :sys.get_state(redix_conn)
:gen_tcp.recv(socket, 0)

But a more correct approach is most likely possible, since you might receive the data you don’t need, which would in turn make other queued requests fail.

I’d probably fork redix and add a way to subscribe for updates, especially if it’s some special redis server.

mayulu

mayulu OP

I got the socket after following your instruction.

:sys.get_state(conn)

returned the following:

{:connected, 
    %Redix.Connection{
        backoff_current: nil, 
        client_reply: :on, 
        connected_address: "127.0.0.1:6379", 
        counter: 0, 
        opts: [
                socket_opts: [], 
                ssl: false, 
                sync_connect: false, 
                backoff_initial: 500, 
                backoff_max: 30000, 
                log: [
                    disconnection: :error, 
                    failed_connection: :error,
                    reconnection: :info
                    ], 
                exit_on_disconnection: false, 
                timeout: 5000, 
                host: '127.0.0.1', 
                port: 6379
            ], 
        socket: #Port<0.9>, 
        socket_owner: #PID<0.180.0>, 
        table: #Reference<0.3121165064.4228775937.104953>, 
        transport: :gen_tcp
    }
}

socket is a Port<0.9>
Then after

:gen_tcp.recv(socket, 0)

It get a error, the socket did not work

{:error, :einval}

But you figured me out, it is not the right way. It should be done in the redis lib.

I should fork Redix or find other redis lib.
(similar to redigo lib in golang, there is a Receive function in such situation.)

Thank you very much.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews