Skip to content

Enable unix sockets for Client creations: - #504

Open
Kropyls wants to merge 2 commits into
aio-libs:masterfrom
Kropyls:master
Open

Enable unix sockets for Client creations:#504
Kropyls wants to merge 2 commits into
aio-libs:masterfrom
Kropyls:master

Conversation

@Kropyls

@Kropyls Kropyls commented Aug 1, 2026

Copy link
Copy Markdown

Fixes: #325

Hey everyone, I saw that this had been sitting in limbo for a while with another PR that seems dead, and this would be a nice-to-have for me in my day-job, so I tried my own take at it. I'm always open to all negative/positive feedback.

What do these changes do?

This enables users to create a Client() with the "path" keyword for users who need a local socket connection. The general idea was to try to do this in a way that didn't break any per-existing consumers of the code, so I forced the path into a keyword argument so all existing behavior goes unaffected.

Details below:

client.py:

  • Flag client now uses a port value of 0 to infer a unix socket
  • holds onto a self._unix boolean (mostly for easy referencing)
  • Client takes overloads for host/port or path combo
  • if path is provided, overwrites any host/port value given

pool.py:

  • change self._host to self._target to make clear that it could be IP or path
  • add self._unix and self._opener values
  • add _make_opener to MemcachePool:
    • this controls generating an opener function that will be slightly different for domain/ip sockets
  • _create_new_conn now calls the self._opener value to open connections

simple.py:

  • add a comment explaining how to use local sockets, and showing that it won't break existing code

commands_test.py:

  • add a test for domain socket setting/setting

conftest.py:

  • build up Params around unix sockets following the existing pattern for IP-based socks
  • fix host assignment in mcache_server_docker

pool_test.py:

  • add test for unix socket aquire/release
  • add a bad path test for local sockets
  • adjust test_bad_connection MemcachePool creation call to work (the new opener pulls host during creation, but it was being changed inside the test originally)

Are there changes in behavior for the user?

I've added a path kwarg they can call, but all per-existing code should still work as is.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes

Kropyls and others added 2 commits July 31, 2026 22:50
Build to be compatable with all pre-existing usages

client.py:
- Flag client now uses a port value of 0 to infer a unix socket
- holds onto a self._unix boolean (mostly for easy referencing)
- Client takes overloads for host/port or path combo
- if path is provided, overwrites any host/port value given

pool.py:
- change self._host to self._target to make clear that it could be IP or path
- add self._unix and self._opener values
- add _make_opener to MemcachePool:
  - this controls generating an opener function that will be slightly different for domain/ip sockets
- _create_new_conn now calls the self._opener value to open connections

simple.py:
- add a comment explaining how to use local sockets, and showing that it won't break existing code

commands_test.py:
- add a test for domain socket setting/setting

conftest.py:
- build up Params around unix sockets following the existing pattern for IP-based socks
- fix host assisnment in mcache_server_docker

pool_test.py:
- add test for unix socket aquire/release
- add a bad path test for local sockets
- adjust test_bad_connection MemcachePool creation call to work (the new opener pulls host during creation, but it was being changed inside the test originally)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UNIX Socket Support

1 participant