On page 349 of the introductory python 3, I write two codes like the one below, but I get an error
What kind of error is this? Similar errors appear in programs in parallel processing.
●redis_pub.py
import redis
import random
conn=redis.Redis()
cats=['siamese', 'personal', 'maine conn', 'norwegian forest']
hats=['stovepipe', 'boowler', 'tam-o-shanter', 'fedora']
for msgin range (10):
cat=random.choice(cats)
hat=random.choice(hats)
print('Publish:%swear a%s'%(cat,hat))
conn.public(cat,hat)
●redis_sub.py
import redis
conn=redis.Redis()
topics=['maine cone', 'personal']
sub=conn.pubsub()
sub.subscribe(topics)
for msg in sub.listen():
if msg ['type'] == 'message':
cat=msg ['channel']
hat=msg ['data']
print('Subscribe: %s wear a%s'%(cat,hat))
I get this error when I boot from the terminal
$python redis_sub.py
Traceback (most recent call last):
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/connection.py", line 439, in connect
sock=self._connect()
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/connection.py", line 494, in_connect
raise err
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/connection.py", line482, in_connect
socket.connect(socket_address)
ConnectionRefusedError: [Errno61] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/client.py", line 2165, in_execute
return command (*args)
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/connection.py", line 538, in send_packaged_command
self.connect()
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exception.ConnectionError: Error 61 connecting to localhost: 6379.Connection refused.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/connection.py", line 439, in connect
sock=self._connect()
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/connection.py", line 494, in_connect
raise err
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/connection.py", line482, in_connect
socket.connect(socket_address)
ConnectionRefusedError: [Errno61] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "redis_sub.py", line 6, in <module>
sub.subscribe(topics)
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/client.py", line2229, insubscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/client.py", line 2172, in_execute
connection.connect()
File"/Users/tadashintaro/anaconda/lib/python 3.6/site-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exception.ConnectionError: Error 61 connecting to localhost: 6379.Connection refused.
redis.exception.ConnectionError: Error 61 connecting to localhost: 6379.Connection refused.
localhost:6379
does not appear to be connected.
Is the Redis server running?
The following command shows the state of the redis process:
psaux | grep redis
If the process is now up, it should look like this:
redis133190.0 2884 1056?Ss10:540:00/usr/bin/redis-server/etc/redis/redis.conf
(It looks like a Mac, so the display may be different.)
© 2024 OneMinuteCode. All rights reserved.