入門python3の３４９ページで下記のような二つのコードを書いているんですがエラーが出ます  
これはどういうエラーなんでしょうか？ 並列処理のところのプログラムで同じようなエラーが出ます。  
●redis_pub.py

```

    import redis
    import random
    
    conn = redis.Redis()
    cats = ['siamese', 'persian', 'maine conn', 'norwegian forest']
    hats = ['stovepipe', 'boowler', 'tam-o-shanter', 'fedora']
    for msg in range(10):
        cat = random.choice(cats)
        hat = random.choice(hats)
        print('Publish: %s wears a %s' % (cat, hat))
        conn.publish(cat, hat)
    
```

●redis_sub.py

```

    import redis
    conn = redis.Redis()
    
    topics = ['maine coon', 'persian']
    sub = conn.pubsub()
    sub.subscribe(topics)
    for msg in sub.listen():
        if msg['type'] == 'message':
            cat = msg['channel']
            hat = msg['data']
            print('Subscribe: %s wears a %s' % (cat, hat))
    
```

ターミナルで起動するとこういうエラーが出ます

[![画像の説明をここに入力](https://i.stack.imgur.com/DXNq5.png)](https://i.stack.imgur.com/DXNq5.png)

```

    $ python redis_sub.py
    Traceback (most recent call last):
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/connection.py", line 439, in connect
        sock = self._connect()
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/connection.py", line 494, in _connect
        raise err
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/connection.py", line 482, in _connect
        sock.connect(socket_address)
    ConnectionRefusedError: [Errno 61] Connection refused
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/client.py", line 2165, in _execute
        return command(*args)
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/connection.py", line 563, in send_command
        self.send_packed_command(self.pack_command(*args))
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/connection.py", line 538, in send_packed_command
        self.connect()
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/connection.py", line 442, in connect
        raise ConnectionError(self._error_message(e))
    redis.exceptions.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/python3.6/site-packages/redis/connection.py", line 439, in connect
        sock = self._connect()
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/connection.py", line 494, in _connect
        raise err
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/connection.py", line 482, in _connect
        sock.connect(socket_address)
    ConnectionRefusedError: [Errno 61] 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/python3.6/site-packages/redis/client.py", line 2229, in subscribe
        ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/client.py", line 2161, in execute_command
        self._execute(connection, connection.send_command, *args)
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/client.py", line 2172, in _execute
        connection.connect()
      File "/Users/tadashintaro/anaconda/lib/python3.6/site-packages/redis/connection.py", line 442, in connect
        raise ConnectionError(self._error_message(e))
    redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
    
```
CC BY-SA 3.0
2017-07-25T19:25:28.340
36674
2017-07-25T22:59:27.657
2017-07-25T20:08:20.397
3605
23690
question
python
Redisを使ってのパブサブシステム
```

    redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
    
```

`localhost:6379` への接続ができていないようです。  
Redisサーバーは起動していますか？  
以下のコマンドでredisプロセスがどのような状態か確認できます。

```

    ps aux | grep redis
    
```

これでプロセスが起動していれば次のように表示されます。

```

    redis    13319  0.0  0.0   2884  1056 ?        Ss   10:54   0:00 /usr/bin/redis-server /etc/redis/redis.conf
    
```

(Macのようなので表示は違うかもしれません）
CC BY-SA 3.0
2017-07-25T22:59:27.657
36676
2017-07-25T22:59:27.657
806
36674
answer