Fixing too many open files on quit command with an explicit socket close, and importing the net module
This commit is contained in:
parent
1a73cef765
commit
135668a7ba
1 changed files with 5 additions and 5 deletions
|
|
@ -14,7 +14,7 @@
|
||||||
## return ``redisNil``, and functions which return a ``RedisList``
|
## return ``redisNil``, and functions which return a ``RedisList``
|
||||||
## may return ``nil``.
|
## may return ``nil``.
|
||||||
|
|
||||||
import sockets, os, strutils, parseutils
|
import net, os, strutils, parseutils
|
||||||
|
|
||||||
const
|
const
|
||||||
redisNil* = "\0\0"
|
redisNil* = "\0\0"
|
||||||
|
|
@ -31,7 +31,7 @@ type
|
||||||
|
|
||||||
type
|
type
|
||||||
Redis* = object
|
Redis* = object
|
||||||
socket: Socket
|
socket: net.Socket
|
||||||
connected: bool
|
connected: bool
|
||||||
pipeline: Pipeline
|
pipeline: Pipeline
|
||||||
|
|
||||||
|
|
@ -55,9 +55,8 @@ proc newPipeline(): Pipeline =
|
||||||
|
|
||||||
proc open*(host = "localhost", port = 6379.Port): Redis =
|
proc open*(host = "localhost", port = 6379.Port): Redis =
|
||||||
## Opens a connection to the redis server.
|
## Opens a connection to the redis server.
|
||||||
result.socket = socket(buffered = false)
|
result.socket = newSocket(buffered = false)
|
||||||
if result.socket == invalidSocket:
|
|
||||||
raiseOSError(osLastError())
|
|
||||||
result.socket.connect(host, port)
|
result.socket.connect(host, port)
|
||||||
result.pipeline = newPipeline()
|
result.pipeline = newPipeline()
|
||||||
|
|
||||||
|
|
@ -923,6 +922,7 @@ proc quit*(r: Redis) =
|
||||||
## Close the connection
|
## Close the connection
|
||||||
r.sendCommand("QUIT")
|
r.sendCommand("QUIT")
|
||||||
raiseNoOK(r.readStatus(), r.pipeline.enabled)
|
raiseNoOK(r.readStatus(), r.pipeline.enabled)
|
||||||
|
r.socket.close()
|
||||||
|
|
||||||
proc select*(r: Redis, index: int): RedisStatus =
|
proc select*(r: Redis, index: int): RedisStatus =
|
||||||
## Change the selected database for the current connection
|
## Change the selected database for the current connection
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue