| 59 | } |
| 60 | |
| 61 | func Sub(local *RESPHandle.WriterHandle, topicName string) (*PubSub, error) { |
| 62 | if _, ok := pss.join[topicName]; !ok { |
| 63 | _, err := JoinPubSub(pss.p2p, "redis-client", topicName) |
| 64 | if err != nil { |
| 65 | log.Println(err) |
| 66 | return nil, err |
| 67 | } |
| 68 | } |
| 69 | lp := fmt.Sprintf("%p", local) |
| 70 | if _, ok := pss.writer[topicName]; !ok { |
| 71 | pss.writer[topicName] = make(map[string]*RESPHandle.WriterHandle) |
| 72 | } |
| 73 | pss.writer[topicName][lp] = local |
| 74 | ps := pss.join[topicName] |
| 75 | return ps, nil |
| 76 | } |
| 77 | |
| 78 | // A structure that represents a PubSub Chat Room |
| 79 | type PubSub struct { |