Böyle, port 6379 tarihinde sunucu soketi oluşturduk:neden bu bağlantı noktasına bağlanabiliyor, ancak python ile yapamıyorum?
Python 13800 IPv4 TCP localhost:6379 (LISTEN)
:
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.bind(('localhost', 6379))
>>> s.listen(1)
lsof bir DİNLE durumundayken gösterir (ben okunabilirlik için lsof bazı köşe kaldırdık)
... şimdi ... KURULAN gösterileri lsof ... ...
>>> s.connect(('localhost', 6379))
bir istemci soketi yapıp bağlayacağız
Python 13800 IPv4 TCP localhost:6379 (LISTEN)
Python 13838 IPv4 TCP localhost:63075->localhost:6379 (ESTABLISHED)
Sonra redis sunucusuna başlıyorum.
Python 13800 IPv4 TCP localhost:6379 (LISTEN)
Python 13838 IPv4 TCP localhost:63075->localhost:6379 (ESTABLISHED)
redis-ser 13855 IPv6 TCP *:6379 (LISTEN)
redis-ser 13855 IPv4 TCP *:6379 (LISTEN)
başka bir bağlantı kurmak için REDIS bir şey eklemek gerekir: Ben lsof görebileceğiniz
>>> r = redis.StrictRedis('localhost', 6379)
>>> r.set('foo', 'bar')
... İşte 6379 kullandığı görünen her şey, lsof nezaketi var. ..
Python 13800 IPv4 TCP localhost:6379 (LISTEN)
Python 13838 IPv4 TCP localhost:63075->localhost:6379 (ESTABLISHED)
redis-ser 13855 IPv6 TCP *:6379 (LISTEN)
redis-ser 13855 IPv4 TCP *:6379 (LISTEN)
redis-ser 13855 IPv6 TCP localhost:6379->localhost:63084 (ESTABLISHED)
Benim sorum şu ki ... eğer bunu ters sırada yaparsam önce "redis-server" komutunu çalıştırın, daha sonra 6379 numaralı bağlantı noktasına bağlı bir soket yapmayı deneyin, "kullanımda olan adres" hatasını alıyorum.
Python zaten olduğunda redis neden kullanılsın, tersi değil mi? Örneğin
... çalışıyor ama bir Python soket yapmaya çalışırsanız çalışır durumdaykenredis --port 1234
...:
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.bind(('localhost', 1234))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 48] Address already in use
title "bind" yerine "connect" yerine düzenlemek için? – dwks