Skip to content

Commit

Permalink
Merge pull request #38 from Zectbumo/master
Browse files Browse the repository at this point in the history
Adding unix socket support
  • Loading branch information
Araq authored Sep 15, 2024
2 parents b341fe2 + ecf81c6 commit b043777
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/redis.nim
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ proc open*(host = "localhost", port = 6379.Port): Redis =

result.socket.connect(host, port)

proc openUnix*(path = "/var/run/redis/redis.sock"): Redis =
## Open a synchronous unix connection to a redis server.
result = Redis(
socket: newSocket(AF_UNIX, SOCK_STREAM, IPPROTO_IP, buffered = false),
pipeline: newPipeline()
)

result.socket.connectUnix(path)

proc openAsync*(host = "localhost", port = 6379.Port): Future[AsyncRedis] {.async.} =
## Open an asynchronous connection to a redis server.
result = AsyncRedis(
Expand All @@ -107,6 +116,16 @@ proc openAsync*(host = "localhost", port = 6379.Port): Future[AsyncRedis] {.asyn

await result.socket.connect(host, port)

proc openUnixAsync*(path = "/var/run/redis/redis.sock"): Future[AsyncRedis] {.async.} =
## Open an asynchronous unix connection to a redis server.
result = AsyncRedis(
socket: newAsyncSocket(AF_UNIX, SOCK_STREAM, IPPROTO_IP, buffered = false),
pipeline: newPipeline(),
sendQueue: initDeque[Future[void]]()
)

await result.socket.connectUnix(path)

proc finaliseCommand(r: Redis | AsyncRedis) =
when r is AsyncRedis:
r.currentCommand = none(string)
Expand Down

0 comments on commit b043777

Please sign in to comment.