| 99 | }; |
| 100 | |
| 101 | static redisAsyncContext *redisAsyncInitialize(redisContext *c) { |
| 102 | redisAsyncContext *ac; |
| 103 | dict *channels = NULL, *patterns = NULL; |
| 104 | |
| 105 | channels = dictCreate(&callbackDict,NULL); |
| 106 | if (channels == NULL) |
| 107 | goto oom; |
| 108 | |
| 109 | patterns = dictCreate(&callbackDict,NULL); |
| 110 | if (patterns == NULL) |
| 111 | goto oom; |
| 112 | |
| 113 | ac = hi_realloc(c,sizeof(redisAsyncContext)); |
| 114 | if (ac == NULL) |
| 115 | goto oom; |
| 116 | |
| 117 | c = &(ac->c); |
| 118 | |
| 119 | /* The regular connect functions will always set the flag REDIS_CONNECTED. |
| 120 | * For the async API, we want to wait until the first write event is |
| 121 | * received up before setting this flag, so reset it here. */ |
| 122 | c->flags &= ~REDIS_CONNECTED; |
| 123 | |
| 124 | ac->err = 0; |
| 125 | ac->errstr = NULL; |
| 126 | ac->data = NULL; |
| 127 | ac->dataCleanup = NULL; |
| 128 | |
| 129 | ac->ev.data = NULL; |
| 130 | ac->ev.addRead = NULL; |
| 131 | ac->ev.delRead = NULL; |
| 132 | ac->ev.addWrite = NULL; |
| 133 | ac->ev.delWrite = NULL; |
| 134 | ac->ev.cleanup = NULL; |
| 135 | ac->ev.scheduleTimer = NULL; |
| 136 | |
| 137 | ac->onConnect = NULL; |
| 138 | ac->onDisconnect = NULL; |
| 139 | |
| 140 | ac->replies.head = NULL; |
| 141 | ac->replies.tail = NULL; |
| 142 | ac->sub.invalid.head = NULL; |
| 143 | ac->sub.invalid.tail = NULL; |
| 144 | ac->sub.channels = channels; |
| 145 | ac->sub.patterns = patterns; |
| 146 | |
| 147 | return ac; |
| 148 | oom: |
| 149 | if (channels) dictRelease(channels); |
| 150 | if (patterns) dictRelease(patterns); |
| 151 | return NULL; |
| 152 | } |
| 153 | |
| 154 | /* We want the error field to be accessible directly instead of requiring |
| 155 | * an indirection to the redisContext struct. */ |
no test coverage detected