redis-server 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. data/LICENSE +38 -0
  2. data/README.md +33 -0
  3. data/bin/redis +114 -0
  4. data/redis/Makefile +5 -0
  5. data/redis/extconf.rb +3 -0
  6. data/redis/redis-2.2.11/00-RELEASENOTES +199 -0
  7. data/redis/redis-2.2.11/BUGS +1 -0
  8. data/redis/redis-2.2.11/CONTRIBUTING +13 -0
  9. data/redis/redis-2.2.11/COPYING +10 -0
  10. data/redis/redis-2.2.11/Changelog +1032 -0
  11. data/redis/redis-2.2.11/INSTALL +30 -0
  12. data/redis/redis-2.2.11/Makefile +22 -0
  13. data/redis/redis-2.2.11/README +83 -0
  14. data/redis/redis-2.2.11/TODO +4 -0
  15. data/redis/redis-2.2.11/client-libraries/README +11 -0
  16. data/redis/redis-2.2.11/deps/hiredis/COPYING +10 -0
  17. data/redis/redis-2.2.11/deps/hiredis/Makefile +115 -0
  18. data/redis/redis-2.2.11/deps/hiredis/README.md +311 -0
  19. data/redis/redis-2.2.11/deps/hiredis/TODO +2 -0
  20. data/redis/redis-2.2.11/deps/hiredis/adapters/ae.h +95 -0
  21. data/redis/redis-2.2.11/deps/hiredis/adapters/libev.h +113 -0
  22. data/redis/redis-2.2.11/deps/hiredis/adapters/libevent.h +76 -0
  23. data/redis/redis-2.2.11/deps/hiredis/async.c +321 -0
  24. data/redis/redis-2.2.11/deps/hiredis/async.h +112 -0
  25. data/redis/redis-2.2.11/deps/hiredis/example-ae.c +53 -0
  26. data/redis/redis-2.2.11/deps/hiredis/example-libev.c +47 -0
  27. data/redis/redis-2.2.11/deps/hiredis/example-libevent.c +48 -0
  28. data/redis/redis-2.2.11/deps/hiredis/example.c +67 -0
  29. data/redis/redis-2.2.11/deps/hiredis/fmacros.h +15 -0
  30. data/redis/redis-2.2.11/deps/hiredis/hiredis.c +1058 -0
  31. data/redis/redis-2.2.11/deps/hiredis/hiredis.h +170 -0
  32. data/redis/redis-2.2.11/deps/hiredis/net.c +170 -0
  33. data/redis/redis-2.2.11/deps/hiredis/net.h +43 -0
  34. data/redis/redis-2.2.11/deps/hiredis/sds.c +479 -0
  35. data/redis/redis-2.2.11/deps/hiredis/sds.h +77 -0
  36. data/redis/redis-2.2.11/deps/hiredis/test.c +479 -0
  37. data/redis/redis-2.2.11/deps/hiredis/util.h +40 -0
  38. data/redis/redis-2.2.11/deps/linenoise/Makefile +10 -0
  39. data/redis/redis-2.2.11/deps/linenoise/README.markdown +45 -0
  40. data/redis/redis-2.2.11/deps/linenoise/example.c +27 -0
  41. data/redis/redis-2.2.11/deps/linenoise/linenoise.c +609 -0
  42. data/redis/redis-2.2.11/deps/linenoise/linenoise.h +55 -0
  43. data/redis/redis-2.2.11/design-documents/REDIS-CLUSTER +214 -0
  44. data/redis/redis-2.2.11/design-documents/REDIS-CLUSTER-2 +343 -0
  45. data/redis/redis-2.2.11/doc/AppendCommand.html +48 -0
  46. data/redis/redis-2.2.11/doc/AppendOnlyFileHowto.html +41 -0
  47. data/redis/redis-2.2.11/doc/AuthCommand.html +39 -0
  48. data/redis/redis-2.2.11/doc/Benchmarks.html +129 -0
  49. data/redis/redis-2.2.11/doc/BgrewriteaofCommand.html +41 -0
  50. data/redis/redis-2.2.11/doc/BgsaveCommand.html +39 -0
  51. data/redis/redis-2.2.11/doc/BlpopCommand.html +51 -0
  52. data/redis/redis-2.2.11/doc/BrpoplpushCommand.html +39 -0
  53. data/redis/redis-2.2.11/doc/CommandReference.html +47 -0
  54. data/redis/redis-2.2.11/doc/Comparisons.html +42 -0
  55. data/redis/redis-2.2.11/doc/ConfigCommand.html +76 -0
  56. data/redis/redis-2.2.11/doc/Configuration.html +38 -0
  57. data/redis/redis-2.2.11/doc/ConnectionHandlingSidebar.html +36 -0
  58. data/redis/redis-2.2.11/doc/ControlCommandsSidebar.html +36 -0
  59. data/redis/redis-2.2.11/doc/Credits.html +38 -0
  60. data/redis/redis-2.2.11/doc/DbsizeCommand.html +38 -0
  61. data/redis/redis-2.2.11/doc/DelCommand.html +41 -0
  62. data/redis/redis-2.2.11/doc/DesignPatterns.html +37 -0
  63. data/redis/redis-2.2.11/doc/EventLibray.html +44 -0
  64. data/redis/redis-2.2.11/doc/ExistsCommand.html +42 -0
  65. data/redis/redis-2.2.11/doc/ExpireCommand.html +96 -0
  66. data/redis/redis-2.2.11/doc/FAQ.html +70 -0
  67. data/redis/redis-2.2.11/doc/Features.html +38 -0
  68. data/redis/redis-2.2.11/doc/FlushallCommand.html +39 -0
  69. data/redis/redis-2.2.11/doc/FlushdbCommand.html +39 -0
  70. data/redis/redis-2.2.11/doc/FromSqlToDataStructures.html +37 -0
  71. data/redis/redis-2.2.11/doc/GenericCommandsSidebar.html +36 -0
  72. data/redis/redis-2.2.11/doc/GetCommand.html +39 -0
  73. data/redis/redis-2.2.11/doc/GetbitCommand.html +39 -0
  74. data/redis/redis-2.2.11/doc/GetsetCommand.html +38 -0
  75. data/redis/redis-2.2.11/doc/HackingStrings.html +83 -0
  76. data/redis/redis-2.2.11/doc/HashCommandsSidebar.html +36 -0
  77. data/redis/redis-2.2.11/doc/Hashes.html +37 -0
  78. data/redis/redis-2.2.11/doc/HdelCommand.html +39 -0
  79. data/redis/redis-2.2.11/doc/HexistsCommand.html +39 -0
  80. data/redis/redis-2.2.11/doc/HgetCommand.html +39 -0
  81. data/redis/redis-2.2.11/doc/HgetallCommand.html +40 -0
  82. data/redis/redis-2.2.11/doc/HincrbyCommand.html +45 -0
  83. data/redis/redis-2.2.11/doc/HlenCommand.html +38 -0
  84. data/redis/redis-2.2.11/doc/HmgetCommand.html +40 -0
  85. data/redis/redis-2.2.11/doc/HmsetCommand.html +40 -0
  86. data/redis/redis-2.2.11/doc/HsetCommand.html +40 -0
  87. data/redis/redis-2.2.11/doc/HsetnxCommand.html +41 -0
  88. data/redis/redis-2.2.11/doc/IncrCommand.html +43 -0
  89. data/redis/redis-2.2.11/doc/InfoCommand.html +48 -0
  90. data/redis/redis-2.2.11/doc/IntroductionToRedisDataTypes.html +152 -0
  91. data/redis/redis-2.2.11/doc/KeysCommand.html +43 -0
  92. data/redis/redis-2.2.11/doc/LastsaveCommand.html +39 -0
  93. data/redis/redis-2.2.11/doc/LindexCommand.html +40 -0
  94. data/redis/redis-2.2.11/doc/ListCommandsSidebar.html +36 -0
  95. data/redis/redis-2.2.11/doc/Lists.html +42 -0
  96. data/redis/redis-2.2.11/doc/LlenCommand.html +41 -0
  97. data/redis/redis-2.2.11/doc/LpopCommand.html +41 -0
  98. data/redis/redis-2.2.11/doc/LrangeCommand.html +47 -0
  99. data/redis/redis-2.2.11/doc/LremCommand.html +41 -0
  100. data/redis/redis-2.2.11/doc/LsetCommand.html +38 -0
  101. data/redis/redis-2.2.11/doc/LtrimCommand.html +47 -0
  102. data/redis/redis-2.2.11/doc/MgetCommand.html +52 -0
  103. data/redis/redis-2.2.11/doc/MonitorCommand.html +63 -0
  104. data/redis/redis-2.2.11/doc/MoveCommand.html +42 -0
  105. data/redis/redis-2.2.11/doc/MsetCommand.html +44 -0
  106. data/redis/redis-2.2.11/doc/MultiExecCommand.html +166 -0
  107. data/redis/redis-2.2.11/doc/NonexistentCommands.html +51 -0
  108. data/redis/redis-2.2.11/doc/ObjectHashMappers.html +39 -0
  109. data/redis/redis-2.2.11/doc/Pipelining.html +36 -0
  110. data/redis/redis-2.2.11/doc/ProgrammingExamples.html +38 -0
  111. data/redis/redis-2.2.11/doc/ProtocolSpecification.html +137 -0
  112. data/redis/redis-2.2.11/doc/PublishSubscribe.html +115 -0
  113. data/redis/redis-2.2.11/doc/QuickStart.html +68 -0
  114. data/redis/redis-2.2.11/doc/QuitCommand.html +38 -0
  115. data/redis/redis-2.2.11/doc/README.html +119 -0
  116. data/redis/redis-2.2.11/doc/RandomkeyCommand.html +39 -0
  117. data/redis/redis-2.2.11/doc/Redis0100ChangeLog.html +67 -0
  118. data/redis/redis-2.2.11/doc/Redis0900ChangeLog.html +56 -0
  119. data/redis/redis-2.2.11/doc/RedisBigData.html +61 -0
  120. data/redis/redis-2.2.11/doc/RedisCLI.html +37 -0
  121. data/redis/redis-2.2.11/doc/RedisEventLibrary.html +70 -0
  122. data/redis/redis-2.2.11/doc/RedisGuides.html +37 -0
  123. data/redis/redis-2.2.11/doc/RedisInternals.html +38 -0
  124. data/redis/redis-2.2.11/doc/RedisPipelining.html +93 -0
  125. data/redis/redis-2.2.11/doc/RedisStatus.html +56 -0
  126. data/redis/redis-2.2.11/doc/Redis_1_2_0_Changelog.html +40 -0
  127. data/redis/redis-2.2.11/doc/Redis_2_0_0_Changelog.html +62 -0
  128. data/redis/redis-2.2.11/doc/Redis_2_0_Whats_new.html +59 -0
  129. data/redis/redis-2.2.11/doc/RenameCommand.html +39 -0
  130. data/redis/redis-2.2.11/doc/RenamenxCommand.html +42 -0
  131. data/redis/redis-2.2.11/doc/ReplicationHowto.html +43 -0
  132. data/redis/redis-2.2.11/doc/ReplyTypes.html +42 -0
  133. data/redis/redis-2.2.11/doc/RoadMap.html +38 -0
  134. data/redis/redis-2.2.11/doc/RpoplpushCommand.html +44 -0
  135. data/redis/redis-2.2.11/doc/RpushCommand.html +40 -0
  136. data/redis/redis-2.2.11/doc/SaddCommand.html +41 -0
  137. data/redis/redis-2.2.11/doc/SaveCommand.html +39 -0
  138. data/redis/redis-2.2.11/doc/ScardCommand.html +41 -0
  139. data/redis/redis-2.2.11/doc/SdiffCommand.html +45 -0
  140. data/redis/redis-2.2.11/doc/SdiffstoreCommand.html +38 -0
  141. data/redis/redis-2.2.11/doc/SelectCommand.html +39 -0
  142. data/redis/redis-2.2.11/doc/SetCommand.html +39 -0
  143. data/redis/redis-2.2.11/doc/SetCommandsSidebar.html +36 -0
  144. data/redis/redis-2.2.11/doc/SetbitCommand.html +45 -0
  145. data/redis/redis-2.2.11/doc/SetexCommand.html +42 -0
  146. data/redis/redis-2.2.11/doc/SetnxCommand.html +51 -0
  147. data/redis/redis-2.2.11/doc/SetrangeCommand.html +58 -0
  148. data/redis/redis-2.2.11/doc/Sets.html +36 -0
  149. data/redis/redis-2.2.11/doc/ShutdownCommand.html +39 -0
  150. data/redis/redis-2.2.11/doc/SideBar.html +36 -0
  151. data/redis/redis-2.2.11/doc/SinterCommand.html +40 -0
  152. data/redis/redis-2.2.11/doc/SinterstoreCommand.html +39 -0
  153. data/redis/redis-2.2.11/doc/SismemberCommand.html +42 -0
  154. data/redis/redis-2.2.11/doc/SlaveofCommand.html +41 -0
  155. data/redis/redis-2.2.11/doc/SmembersCommand.html +38 -0
  156. data/redis/redis-2.2.11/doc/SmoveCommand.html +44 -0
  157. data/redis/redis-2.2.11/doc/SortCommand.html +75 -0
  158. data/redis/redis-2.2.11/doc/SortedSetCommandsSidebar.html +36 -0
  159. data/redis/redis-2.2.11/doc/SortedSets.html +36 -0
  160. data/redis/redis-2.2.11/doc/Speed.html +38 -0
  161. data/redis/redis-2.2.11/doc/SponsorshipHistory.html +38 -0
  162. data/redis/redis-2.2.11/doc/SpopCommand.html +40 -0
  163. data/redis/redis-2.2.11/doc/SrandmemberCommand.html +40 -0
  164. data/redis/redis-2.2.11/doc/SremCommand.html +42 -0
  165. data/redis/redis-2.2.11/doc/StringCommandsSidebar.html +36 -0
  166. data/redis/redis-2.2.11/doc/Strings.html +37 -0
  167. data/redis/redis-2.2.11/doc/StrlenCommand.html +39 -0
  168. data/redis/redis-2.2.11/doc/SubstrCommand.html +52 -0
  169. data/redis/redis-2.2.11/doc/SunionCommand.html +40 -0
  170. data/redis/redis-2.2.11/doc/SunionstoreCommand.html +38 -0
  171. data/redis/redis-2.2.11/doc/SupportedLanguages.html +60 -0
  172. data/redis/redis-2.2.11/doc/SupportedPlatforms.html +37 -0
  173. data/redis/redis-2.2.11/doc/TemplateCommand.html +38 -0
  174. data/redis/redis-2.2.11/doc/TtlCommand.html +38 -0
  175. data/redis/redis-2.2.11/doc/TwitterAlikeExample.html +250 -0
  176. data/redis/redis-2.2.11/doc/TypeCommand.html +46 -0
  177. data/redis/redis-2.2.11/doc/UnstableSource.html +39 -0
  178. data/redis/redis-2.2.11/doc/VirtualMemorySpecification.html +156 -0
  179. data/redis/redis-2.2.11/doc/VirtualMemoryUserGuide.html +66 -0
  180. data/redis/redis-2.2.11/doc/ZaddCommand.html +43 -0
  181. data/redis/redis-2.2.11/doc/ZcardCommand.html +41 -0
  182. data/redis/redis-2.2.11/doc/ZincrbyCommand.html +42 -0
  183. data/redis/redis-2.2.11/doc/ZrangeCommand.html +42 -0
  184. data/redis/redis-2.2.11/doc/ZrangebyscoreCommand.html +77 -0
  185. data/redis/redis-2.2.11/doc/ZrankCommand.html +43 -0
  186. data/redis/redis-2.2.11/doc/ZremCommand.html +42 -0
  187. data/redis/redis-2.2.11/doc/ZremrangebyrankCommand.html +39 -0
  188. data/redis/redis-2.2.11/doc/ZremrangebyscoreCommand.html +39 -0
  189. data/redis/redis-2.2.11/doc/ZscoreCommand.html +41 -0
  190. data/redis/redis-2.2.11/doc/ZunionCommand.html +42 -0
  191. data/redis/redis-2.2.11/doc/ZunionstoreCommand.html +43 -0
  192. data/redis/redis-2.2.11/doc/index.html +43 -0
  193. data/redis/redis-2.2.11/doc/redis.png +0 -0
  194. data/redis/redis-2.2.11/doc/style.css +25 -0
  195. data/redis/redis-2.2.11/redis.conf +417 -0
  196. data/redis/redis-2.2.11/src/Makefile +177 -0
  197. data/redis/redis-2.2.11/src/adlist.c +325 -0
  198. data/redis/redis-2.2.11/src/adlist.h +92 -0
  199. data/redis/redis-2.2.11/src/ae.c +390 -0
  200. data/redis/redis-2.2.11/src/ae.h +117 -0
  201. data/redis/redis-2.2.11/src/ae_epoll.c +91 -0
  202. data/redis/redis-2.2.11/src/ae_kqueue.c +93 -0
  203. data/redis/redis-2.2.11/src/ae_select.c +72 -0
  204. data/redis/redis-2.2.11/src/anet.c +347 -0
  205. data/redis/redis-2.2.11/src/anet.h +57 -0
  206. data/redis/redis-2.2.11/src/aof.c +675 -0
  207. data/redis/redis-2.2.11/src/config.c +627 -0
  208. data/redis/redis-2.2.11/src/config.h +64 -0
  209. data/redis/redis-2.2.11/src/db.c +543 -0
  210. data/redis/redis-2.2.11/src/debug.c +314 -0
  211. data/redis/redis-2.2.11/src/dict.c +721 -0
  212. data/redis/redis-2.2.11/src/dict.h +156 -0
  213. data/redis/redis-2.2.11/src/fmacros.h +15 -0
  214. data/redis/redis-2.2.11/src/help.h +638 -0
  215. data/redis/redis-2.2.11/src/intset.c +422 -0
  216. data/redis/redis-2.2.11/src/intset.h +19 -0
  217. data/redis/redis-2.2.11/src/lzf.h +100 -0
  218. data/redis/redis-2.2.11/src/lzfP.h +159 -0
  219. data/redis/redis-2.2.11/src/lzf_c.c +295 -0
  220. data/redis/redis-2.2.11/src/lzf_d.c +150 -0
  221. data/redis/redis-2.2.11/src/mkreleasehdr.sh +9 -0
  222. data/redis/redis-2.2.11/src/multi.c +268 -0
  223. data/redis/redis-2.2.11/src/networking.c +899 -0
  224. data/redis/redis-2.2.11/src/object.c +484 -0
  225. data/redis/redis-2.2.11/src/pqsort.c +197 -0
  226. data/redis/redis-2.2.11/src/pqsort.h +15 -0
  227. data/redis/redis-2.2.11/src/pubsub.c +267 -0
  228. data/redis/redis-2.2.11/src/rdb.c +1020 -0
  229. data/redis/redis-2.2.11/src/redis-benchmark.c +530 -0
  230. data/redis/redis-2.2.11/src/redis-check-aof.c +185 -0
  231. data/redis/redis-2.2.11/src/redis-check-dump.c +681 -0
  232. data/redis/redis-2.2.11/src/redis-cli.c +773 -0
  233. data/redis/redis-2.2.11/src/redis.c +1677 -0
  234. data/redis/redis-2.2.11/src/redis.h +1022 -0
  235. data/redis/redis-2.2.11/src/release.c +13 -0
  236. data/redis/redis-2.2.11/src/replication.c +557 -0
  237. data/redis/redis-2.2.11/src/sds.c +639 -0
  238. data/redis/redis-2.2.11/src/sds.h +78 -0
  239. data/redis/redis-2.2.11/src/sha1.c +276 -0
  240. data/redis/redis-2.2.11/src/sha1.h +17 -0
  241. data/redis/redis-2.2.11/src/solarisfixes.h +22 -0
  242. data/redis/redis-2.2.11/src/sort.c +389 -0
  243. data/redis/redis-2.2.11/src/syncio.c +154 -0
  244. data/redis/redis-2.2.11/src/t_hash.c +476 -0
  245. data/redis/redis-2.2.11/src/t_list.c +986 -0
  246. data/redis/redis-2.2.11/src/t_set.c +610 -0
  247. data/redis/redis-2.2.11/src/t_string.c +438 -0
  248. data/redis/redis-2.2.11/src/t_zset.c +1084 -0
  249. data/redis/redis-2.2.11/src/testhelp.h +54 -0
  250. data/redis/redis-2.2.11/src/util.c +243 -0
  251. data/redis/redis-2.2.11/src/valgrind.sup +5 -0
  252. data/redis/redis-2.2.11/src/version.h +1 -0
  253. data/redis/redis-2.2.11/src/vm.c +1149 -0
  254. data/redis/redis-2.2.11/src/ziplist.c +1323 -0
  255. data/redis/redis-2.2.11/src/ziplist.h +15 -0
  256. data/redis/redis-2.2.11/src/zipmap.c +455 -0
  257. data/redis/redis-2.2.11/src/zipmap.h +48 -0
  258. data/redis/redis-2.2.11/src/zmalloc.c +278 -0
  259. data/redis/redis-2.2.11/src/zmalloc.h +47 -0
  260. data/redis/redis-2.2.11/tests/assets/default.conf +308 -0
  261. data/redis/redis-2.2.11/tests/integration/aof.tcl +104 -0
  262. data/redis/redis-2.2.11/tests/integration/redis-cli.tcl +208 -0
  263. data/redis/redis-2.2.11/tests/integration/replication.tcl +98 -0
  264. data/redis/redis-2.2.11/tests/support/redis.tcl +241 -0
  265. data/redis/redis-2.2.11/tests/support/server.tcl +294 -0
  266. data/redis/redis-2.2.11/tests/support/test.tcl +190 -0
  267. data/redis/redis-2.2.11/tests/support/tmpfile.tcl +15 -0
  268. data/redis/redis-2.2.11/tests/support/util.tcl +296 -0
  269. data/redis/redis-2.2.11/tests/test_helper.tcl +221 -0
  270. data/redis/redis-2.2.11/tests/unit/auth.tcl +15 -0
  271. data/redis/redis-2.2.11/tests/unit/basic.tcl +616 -0
  272. data/redis/redis-2.2.11/tests/unit/cas.tcl +135 -0
  273. data/redis/redis-2.2.11/tests/unit/expire.tcl +74 -0
  274. data/redis/redis-2.2.11/tests/unit/other.tcl +240 -0
  275. data/redis/redis-2.2.11/tests/unit/printver.tcl +6 -0
  276. data/redis/redis-2.2.11/tests/unit/protocol.tcl +62 -0
  277. data/redis/redis-2.2.11/tests/unit/pubsub.tcl +195 -0
  278. data/redis/redis-2.2.11/tests/unit/quit.tcl +40 -0
  279. data/redis/redis-2.2.11/tests/unit/sort.tcl +189 -0
  280. data/redis/redis-2.2.11/tests/unit/type/hash.tcl +300 -0
  281. data/redis/redis-2.2.11/tests/unit/type/list.tcl +819 -0
  282. data/redis/redis-2.2.11/tests/unit/type/set.tcl +334 -0
  283. data/redis/redis-2.2.11/tests/unit/type/zset.tcl +587 -0
  284. data/redis/redis-2.2.11/utils/build-static-symbols.tcl +22 -0
  285. data/redis/redis-2.2.11/utils/generate-command-help.rb +112 -0
  286. data/redis/redis-2.2.11/utils/mktarball.sh +13 -0
  287. data/redis/redis-2.2.11/utils/redis-copy.rb +78 -0
  288. data/redis/redis-2.2.11/utils/redis-sha1.rb +52 -0
  289. data/redis/redis-2.2.11/utils/redis_init_script +42 -0
  290. metadata +362 -0
@@ -0,0 +1,13 @@
1
+ /* Every time the Redis Git SHA1 or Dirty status changes only this file
2
+ * small file is recompiled, as we access this information in all the other
3
+ * files using this functions. */
4
+
5
+ #include "release.h"
6
+
7
+ char *redisGitSHA1(void) {
8
+ return REDIS_GIT_SHA1;
9
+ }
10
+
11
+ char *redisGitDirty(void) {
12
+ return REDIS_GIT_DIRTY;
13
+ }
@@ -0,0 +1,557 @@
1
+ #include "redis.h"
2
+
3
+ #include <sys/time.h>
4
+ #include <unistd.h>
5
+ #include <fcntl.h>
6
+ #include <sys/stat.h>
7
+
8
+ /* ---------------------------------- MASTER -------------------------------- */
9
+
10
+ void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc) {
11
+ listNode *ln;
12
+ listIter li;
13
+ int outc = 0, j;
14
+ robj **outv;
15
+ /* We need 1+(ARGS*3) objects since commands are using the new protocol
16
+ * and we one 1 object for the first "*<count>\r\n" multibulk count, then
17
+ * for every additional object we have "$<count>\r\n" + object + "\r\n". */
18
+ robj *static_outv[REDIS_STATIC_ARGS*3+1];
19
+ robj *lenobj;
20
+
21
+ if (argc <= REDIS_STATIC_ARGS) {
22
+ outv = static_outv;
23
+ } else {
24
+ outv = zmalloc(sizeof(robj*)*(argc*3+1));
25
+ }
26
+
27
+ lenobj = createObject(REDIS_STRING,
28
+ sdscatprintf(sdsempty(), "*%d\r\n", argc));
29
+ lenobj->refcount = 0;
30
+ outv[outc++] = lenobj;
31
+ for (j = 0; j < argc; j++) {
32
+ lenobj = createObject(REDIS_STRING,
33
+ sdscatprintf(sdsempty(),"$%lu\r\n",
34
+ (unsigned long) stringObjectLen(argv[j])));
35
+ lenobj->refcount = 0;
36
+ outv[outc++] = lenobj;
37
+ outv[outc++] = argv[j];
38
+ outv[outc++] = shared.crlf;
39
+ }
40
+
41
+ /* Increment all the refcounts at start and decrement at end in order to
42
+ * be sure to free objects if there is no slave in a replication state
43
+ * able to be feed with commands */
44
+ for (j = 0; j < outc; j++) incrRefCount(outv[j]);
45
+ listRewind(slaves,&li);
46
+ while((ln = listNext(&li))) {
47
+ redisClient *slave = ln->value;
48
+
49
+ /* Don't feed slaves that are still waiting for BGSAVE to start */
50
+ if (slave->replstate == REDIS_REPL_WAIT_BGSAVE_START) continue;
51
+
52
+ /* Feed all the other slaves, MONITORs and so on */
53
+ if (slave->slaveseldb != dictid) {
54
+ robj *selectcmd;
55
+
56
+ switch(dictid) {
57
+ case 0: selectcmd = shared.select0; break;
58
+ case 1: selectcmd = shared.select1; break;
59
+ case 2: selectcmd = shared.select2; break;
60
+ case 3: selectcmd = shared.select3; break;
61
+ case 4: selectcmd = shared.select4; break;
62
+ case 5: selectcmd = shared.select5; break;
63
+ case 6: selectcmd = shared.select6; break;
64
+ case 7: selectcmd = shared.select7; break;
65
+ case 8: selectcmd = shared.select8; break;
66
+ case 9: selectcmd = shared.select9; break;
67
+ default:
68
+ selectcmd = createObject(REDIS_STRING,
69
+ sdscatprintf(sdsempty(),"select %d\r\n",dictid));
70
+ selectcmd->refcount = 0;
71
+ break;
72
+ }
73
+ addReply(slave,selectcmd);
74
+ slave->slaveseldb = dictid;
75
+ }
76
+ for (j = 0; j < outc; j++) addReply(slave,outv[j]);
77
+ }
78
+ for (j = 0; j < outc; j++) decrRefCount(outv[j]);
79
+ if (outv != static_outv) zfree(outv);
80
+ }
81
+
82
+ void replicationFeedMonitors(list *monitors, int dictid, robj **argv, int argc) {
83
+ listNode *ln;
84
+ listIter li;
85
+ int j;
86
+ sds cmdrepr = sdsnew("+");
87
+ robj *cmdobj;
88
+ struct timeval tv;
89
+
90
+ gettimeofday(&tv,NULL);
91
+ cmdrepr = sdscatprintf(cmdrepr,"%ld.%06ld ",(long)tv.tv_sec,(long)tv.tv_usec);
92
+ if (dictid != 0) cmdrepr = sdscatprintf(cmdrepr,"(db %d) ", dictid);
93
+
94
+ for (j = 0; j < argc; j++) {
95
+ if (argv[j]->encoding == REDIS_ENCODING_INT) {
96
+ cmdrepr = sdscatprintf(cmdrepr, "\"%ld\"", (long)argv[j]->ptr);
97
+ } else {
98
+ cmdrepr = sdscatrepr(cmdrepr,(char*)argv[j]->ptr,
99
+ sdslen(argv[j]->ptr));
100
+ }
101
+ if (j != argc-1)
102
+ cmdrepr = sdscatlen(cmdrepr," ",1);
103
+ }
104
+ cmdrepr = sdscatlen(cmdrepr,"\r\n",2);
105
+ cmdobj = createObject(REDIS_STRING,cmdrepr);
106
+
107
+ listRewind(monitors,&li);
108
+ while((ln = listNext(&li))) {
109
+ redisClient *monitor = ln->value;
110
+ addReply(monitor,cmdobj);
111
+ }
112
+ decrRefCount(cmdobj);
113
+ }
114
+
115
+ void syncCommand(redisClient *c) {
116
+ /* ignore SYNC if aleady slave or in monitor mode */
117
+ if (c->flags & REDIS_SLAVE) return;
118
+
119
+ /* Refuse SYNC requests if we are a slave but the link with our master
120
+ * is not ok... */
121
+ if (server.masterhost && server.replstate != REDIS_REPL_CONNECTED) {
122
+ addReplyError(c,"Can't SYNC while not connected with my master");
123
+ return;
124
+ }
125
+
126
+ /* SYNC can't be issued when the server has pending data to send to
127
+ * the client about already issued commands. We need a fresh reply
128
+ * buffer registering the differences between the BGSAVE and the current
129
+ * dataset, so that we can copy to other slaves if needed. */
130
+ if (listLength(c->reply) != 0) {
131
+ addReplyError(c,"SYNC is invalid with pending input");
132
+ return;
133
+ }
134
+
135
+ redisLog(REDIS_NOTICE,"Slave ask for synchronization");
136
+ /* Here we need to check if there is a background saving operation
137
+ * in progress, or if it is required to start one */
138
+ if (server.bgsavechildpid != -1) {
139
+ /* Ok a background save is in progress. Let's check if it is a good
140
+ * one for replication, i.e. if there is another slave that is
141
+ * registering differences since the server forked to save */
142
+ redisClient *slave;
143
+ listNode *ln;
144
+ listIter li;
145
+
146
+ listRewind(server.slaves,&li);
147
+ while((ln = listNext(&li))) {
148
+ slave = ln->value;
149
+ if (slave->replstate == REDIS_REPL_WAIT_BGSAVE_END) break;
150
+ }
151
+ if (ln) {
152
+ /* Perfect, the server is already registering differences for
153
+ * another slave. Set the right state, and copy the buffer. */
154
+ listRelease(c->reply);
155
+ c->reply = listDup(slave->reply);
156
+ c->replstate = REDIS_REPL_WAIT_BGSAVE_END;
157
+ redisLog(REDIS_NOTICE,"Waiting for end of BGSAVE for SYNC");
158
+ } else {
159
+ /* No way, we need to wait for the next BGSAVE in order to
160
+ * register differences */
161
+ c->replstate = REDIS_REPL_WAIT_BGSAVE_START;
162
+ redisLog(REDIS_NOTICE,"Waiting for next BGSAVE for SYNC");
163
+ }
164
+ } else {
165
+ /* Ok we don't have a BGSAVE in progress, let's start one */
166
+ redisLog(REDIS_NOTICE,"Starting BGSAVE for SYNC");
167
+ if (rdbSaveBackground(server.dbfilename) != REDIS_OK) {
168
+ redisLog(REDIS_NOTICE,"Replication failed, can't BGSAVE");
169
+ addReplyError(c,"Unable to perform background save");
170
+ return;
171
+ }
172
+ c->replstate = REDIS_REPL_WAIT_BGSAVE_END;
173
+ }
174
+ c->repldbfd = -1;
175
+ c->flags |= REDIS_SLAVE;
176
+ c->slaveseldb = 0;
177
+ listAddNodeTail(server.slaves,c);
178
+ return;
179
+ }
180
+
181
+ void sendBulkToSlave(aeEventLoop *el, int fd, void *privdata, int mask) {
182
+ redisClient *slave = privdata;
183
+ REDIS_NOTUSED(el);
184
+ REDIS_NOTUSED(mask);
185
+ char buf[REDIS_IOBUF_LEN];
186
+ ssize_t nwritten, buflen;
187
+
188
+ if (slave->repldboff == 0) {
189
+ /* Write the bulk write count before to transfer the DB. In theory here
190
+ * we don't know how much room there is in the output buffer of the
191
+ * socket, but in pratice SO_SNDLOWAT (the minimum count for output
192
+ * operations) will never be smaller than the few bytes we need. */
193
+ sds bulkcount;
194
+
195
+ bulkcount = sdscatprintf(sdsempty(),"$%lld\r\n",(unsigned long long)
196
+ slave->repldbsize);
197
+ if (write(fd,bulkcount,sdslen(bulkcount)) != (signed)sdslen(bulkcount))
198
+ {
199
+ sdsfree(bulkcount);
200
+ freeClient(slave);
201
+ return;
202
+ }
203
+ sdsfree(bulkcount);
204
+ }
205
+ lseek(slave->repldbfd,slave->repldboff,SEEK_SET);
206
+ buflen = read(slave->repldbfd,buf,REDIS_IOBUF_LEN);
207
+ if (buflen <= 0) {
208
+ redisLog(REDIS_WARNING,"Read error sending DB to slave: %s",
209
+ (buflen == 0) ? "premature EOF" : strerror(errno));
210
+ freeClient(slave);
211
+ return;
212
+ }
213
+ if ((nwritten = write(fd,buf,buflen)) == -1) {
214
+ redisLog(REDIS_VERBOSE,"Write error sending DB to slave: %s",
215
+ strerror(errno));
216
+ freeClient(slave);
217
+ return;
218
+ }
219
+ slave->repldboff += nwritten;
220
+ if (slave->repldboff == slave->repldbsize) {
221
+ close(slave->repldbfd);
222
+ slave->repldbfd = -1;
223
+ aeDeleteFileEvent(server.el,slave->fd,AE_WRITABLE);
224
+ slave->replstate = REDIS_REPL_ONLINE;
225
+ if (aeCreateFileEvent(server.el, slave->fd, AE_WRITABLE,
226
+ sendReplyToClient, slave) == AE_ERR) {
227
+ freeClient(slave);
228
+ return;
229
+ }
230
+ addReplySds(slave,sdsempty());
231
+ redisLog(REDIS_NOTICE,"Synchronization with slave succeeded");
232
+ }
233
+ }
234
+
235
+ /* This function is called at the end of every backgrond saving.
236
+ * The argument bgsaveerr is REDIS_OK if the background saving succeeded
237
+ * otherwise REDIS_ERR is passed to the function.
238
+ *
239
+ * The goal of this function is to handle slaves waiting for a successful
240
+ * background saving in order to perform non-blocking synchronization. */
241
+ void updateSlavesWaitingBgsave(int bgsaveerr) {
242
+ listNode *ln;
243
+ int startbgsave = 0;
244
+ listIter li;
245
+
246
+ listRewind(server.slaves,&li);
247
+ while((ln = listNext(&li))) {
248
+ redisClient *slave = ln->value;
249
+
250
+ if (slave->replstate == REDIS_REPL_WAIT_BGSAVE_START) {
251
+ startbgsave = 1;
252
+ slave->replstate = REDIS_REPL_WAIT_BGSAVE_END;
253
+ } else if (slave->replstate == REDIS_REPL_WAIT_BGSAVE_END) {
254
+ struct redis_stat buf;
255
+
256
+ if (bgsaveerr != REDIS_OK) {
257
+ freeClient(slave);
258
+ redisLog(REDIS_WARNING,"SYNC failed. BGSAVE child returned an error");
259
+ continue;
260
+ }
261
+ if ((slave->repldbfd = open(server.dbfilename,O_RDONLY)) == -1 ||
262
+ redis_fstat(slave->repldbfd,&buf) == -1) {
263
+ freeClient(slave);
264
+ redisLog(REDIS_WARNING,"SYNC failed. Can't open/stat DB after BGSAVE: %s", strerror(errno));
265
+ continue;
266
+ }
267
+ slave->repldboff = 0;
268
+ slave->repldbsize = buf.st_size;
269
+ slave->replstate = REDIS_REPL_SEND_BULK;
270
+ aeDeleteFileEvent(server.el,slave->fd,AE_WRITABLE);
271
+ if (aeCreateFileEvent(server.el, slave->fd, AE_WRITABLE, sendBulkToSlave, slave) == AE_ERR) {
272
+ freeClient(slave);
273
+ continue;
274
+ }
275
+ }
276
+ }
277
+ if (startbgsave) {
278
+ if (rdbSaveBackground(server.dbfilename) != REDIS_OK) {
279
+ listIter li;
280
+
281
+ listRewind(server.slaves,&li);
282
+ redisLog(REDIS_WARNING,"SYNC failed. BGSAVE failed");
283
+ while((ln = listNext(&li))) {
284
+ redisClient *slave = ln->value;
285
+
286
+ if (slave->replstate == REDIS_REPL_WAIT_BGSAVE_START)
287
+ freeClient(slave);
288
+ }
289
+ }
290
+ }
291
+ }
292
+
293
+ /* ----------------------------------- SLAVE -------------------------------- */
294
+
295
+ /* Abort the async download of the bulk dataset while SYNC-ing with master */
296
+ void replicationAbortSyncTransfer(void) {
297
+ redisAssert(server.replstate == REDIS_REPL_TRANSFER);
298
+
299
+ aeDeleteFileEvent(server.el,server.repl_transfer_s,AE_READABLE);
300
+ close(server.repl_transfer_s);
301
+ close(server.repl_transfer_fd);
302
+ unlink(server.repl_transfer_tmpfile);
303
+ zfree(server.repl_transfer_tmpfile);
304
+ server.replstate = REDIS_REPL_CONNECT;
305
+ }
306
+
307
+ /* Asynchronously read the SYNC payload we receive from a master */
308
+ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
309
+ char buf[4096];
310
+ ssize_t nread, readlen;
311
+ REDIS_NOTUSED(el);
312
+ REDIS_NOTUSED(privdata);
313
+ REDIS_NOTUSED(mask);
314
+
315
+ /* If repl_transfer_left == -1 we still have to read the bulk length
316
+ * from the master reply. */
317
+ if (server.repl_transfer_left == -1) {
318
+ if (syncReadLine(fd,buf,1024,3600) == -1) {
319
+ redisLog(REDIS_WARNING,
320
+ "I/O error reading bulk count from MASTER: %s",
321
+ strerror(errno));
322
+ replicationAbortSyncTransfer();
323
+ return;
324
+ }
325
+ if (buf[0] == '-') {
326
+ redisLog(REDIS_WARNING,
327
+ "MASTER aborted replication with an error: %s",
328
+ buf+1);
329
+ replicationAbortSyncTransfer();
330
+ return;
331
+ } else if (buf[0] == '\0') {
332
+ /* At this stage just a newline works as a PING in order to take
333
+ * the connection live. So we refresh our last interaction
334
+ * timestamp. */
335
+ server.repl_transfer_lastio = time(NULL);
336
+ return;
337
+ } else if (buf[0] != '$') {
338
+ redisLog(REDIS_WARNING,"Bad protocol from MASTER, the first byte is not '$', are you sure the host and port are right?");
339
+ replicationAbortSyncTransfer();
340
+ return;
341
+ }
342
+ server.repl_transfer_left = strtol(buf+1,NULL,10);
343
+ redisLog(REDIS_NOTICE,
344
+ "MASTER <-> SLAVE sync: receiving %ld bytes from master",
345
+ server.repl_transfer_left);
346
+ return;
347
+ }
348
+
349
+ /* Read bulk data */
350
+ readlen = (server.repl_transfer_left < (signed)sizeof(buf)) ?
351
+ server.repl_transfer_left : (signed)sizeof(buf);
352
+ nread = read(fd,buf,readlen);
353
+ if (nread <= 0) {
354
+ redisLog(REDIS_WARNING,"I/O error trying to sync with MASTER: %s",
355
+ (nread == -1) ? strerror(errno) : "connection lost");
356
+ replicationAbortSyncTransfer();
357
+ return;
358
+ }
359
+ server.repl_transfer_lastio = time(NULL);
360
+ if (write(server.repl_transfer_fd,buf,nread) != nread) {
361
+ redisLog(REDIS_WARNING,"Write error or short write writing to the DB dump file needed for MASTER <-> SLAVE synchrnonization: %s", strerror(errno));
362
+ replicationAbortSyncTransfer();
363
+ return;
364
+ }
365
+ server.repl_transfer_left -= nread;
366
+ /* Check if the transfer is now complete */
367
+ if (server.repl_transfer_left == 0) {
368
+ if (rename(server.repl_transfer_tmpfile,server.dbfilename) == -1) {
369
+ redisLog(REDIS_WARNING,"Failed trying to rename the temp DB into dump.rdb in MASTER <-> SLAVE synchronization: %s", strerror(errno));
370
+ replicationAbortSyncTransfer();
371
+ return;
372
+ }
373
+ redisLog(REDIS_NOTICE, "MASTER <-> SLAVE sync: Loading DB in memory");
374
+ emptyDb();
375
+ /* Before loading the DB into memory we need to delete the readable
376
+ * handler, otherwise it will get called recursively since
377
+ * rdbLoad() will call the event loop to process events from time to
378
+ * time for non blocking loading. */
379
+ aeDeleteFileEvent(server.el,server.repl_transfer_s,AE_READABLE);
380
+ if (rdbLoad(server.dbfilename) != REDIS_OK) {
381
+ redisLog(REDIS_WARNING,"Failed trying to load the MASTER synchronization DB from disk");
382
+ replicationAbortSyncTransfer();
383
+ return;
384
+ }
385
+ /* Final setup of the connected slave <- master link */
386
+ zfree(server.repl_transfer_tmpfile);
387
+ close(server.repl_transfer_fd);
388
+ server.master = createClient(server.repl_transfer_s);
389
+ server.master->flags |= REDIS_MASTER;
390
+ server.master->authenticated = 1;
391
+ server.replstate = REDIS_REPL_CONNECTED;
392
+ redisLog(REDIS_NOTICE, "MASTER <-> SLAVE sync: Finished with success");
393
+ /* Rewrite the AOF file now that the dataset changed. */
394
+ if (server.appendonly) rewriteAppendOnlyFileBackground();
395
+ }
396
+ }
397
+
398
+ int syncWithMaster(void) {
399
+ char buf[1024], tmpfile[256], authcmd[1024];
400
+ int fd = anetTcpConnect(NULL,server.masterhost,server.masterport);
401
+ int dfd, maxtries = 5;
402
+
403
+ if (fd == -1) {
404
+ redisLog(REDIS_WARNING,"Unable to connect to MASTER: %s",
405
+ strerror(errno));
406
+ return REDIS_ERR;
407
+ }
408
+
409
+ /* AUTH with the master if required. */
410
+ if(server.masterauth) {
411
+ snprintf(authcmd, 1024, "AUTH %s\r\n", server.masterauth);
412
+ if (syncWrite(fd, authcmd, strlen(server.masterauth)+7, 5) == -1) {
413
+ close(fd);
414
+ redisLog(REDIS_WARNING,"Unable to AUTH to MASTER: %s",
415
+ strerror(errno));
416
+ return REDIS_ERR;
417
+ }
418
+ /* Read the AUTH result. */
419
+ if (syncReadLine(fd,buf,1024,3600) == -1) {
420
+ close(fd);
421
+ redisLog(REDIS_WARNING,"I/O error reading auth result from MASTER: %s",
422
+ strerror(errno));
423
+ return REDIS_ERR;
424
+ }
425
+ if (buf[0] != '+') {
426
+ close(fd);
427
+ redisLog(REDIS_WARNING,"Cannot AUTH to MASTER, is the masterauth password correct?");
428
+ return REDIS_ERR;
429
+ }
430
+ }
431
+
432
+ /* Issue the SYNC command */
433
+ if (syncWrite(fd,"SYNC \r\n",7,5) == -1) {
434
+ close(fd);
435
+ redisLog(REDIS_WARNING,"I/O error writing to MASTER: %s",
436
+ strerror(errno));
437
+ return REDIS_ERR;
438
+ }
439
+
440
+ /* Prepare a suitable temp file for bulk transfer */
441
+ while(maxtries--) {
442
+ snprintf(tmpfile,256,
443
+ "temp-%d.%ld.rdb",(int)time(NULL),(long int)getpid());
444
+ dfd = open(tmpfile,O_CREAT|O_WRONLY|O_EXCL,0644);
445
+ if (dfd != -1) break;
446
+ sleep(1);
447
+ }
448
+ if (dfd == -1) {
449
+ close(fd);
450
+ redisLog(REDIS_WARNING,"Opening the temp file needed for MASTER <-> SLAVE synchronization: %s",strerror(errno));
451
+ return REDIS_ERR;
452
+ }
453
+
454
+ /* Setup the non blocking download of the bulk file. */
455
+ if (aeCreateFileEvent(server.el, fd, AE_READABLE, readSyncBulkPayload, NULL)
456
+ == AE_ERR)
457
+ {
458
+ close(fd);
459
+ redisLog(REDIS_WARNING,"Can't create readable event for SYNC");
460
+ return REDIS_ERR;
461
+ }
462
+ server.replstate = REDIS_REPL_TRANSFER;
463
+ server.repl_transfer_left = -1;
464
+ server.repl_transfer_s = fd;
465
+ server.repl_transfer_fd = dfd;
466
+ server.repl_transfer_lastio = time(NULL);
467
+ server.repl_transfer_tmpfile = zstrdup(tmpfile);
468
+ return REDIS_OK;
469
+ }
470
+
471
+ void slaveofCommand(redisClient *c) {
472
+ if (!strcasecmp(c->argv[1]->ptr,"no") &&
473
+ !strcasecmp(c->argv[2]->ptr,"one")) {
474
+ if (server.masterhost) {
475
+ sdsfree(server.masterhost);
476
+ server.masterhost = NULL;
477
+ if (server.master) freeClient(server.master);
478
+ if (server.replstate == REDIS_REPL_TRANSFER)
479
+ replicationAbortSyncTransfer();
480
+ server.replstate = REDIS_REPL_NONE;
481
+ redisLog(REDIS_NOTICE,"MASTER MODE enabled (user request)");
482
+ }
483
+ } else {
484
+ sdsfree(server.masterhost);
485
+ server.masterhost = sdsdup(c->argv[1]->ptr);
486
+ server.masterport = atoi(c->argv[2]->ptr);
487
+ if (server.master) freeClient(server.master);
488
+ if (server.replstate == REDIS_REPL_TRANSFER)
489
+ replicationAbortSyncTransfer();
490
+ server.replstate = REDIS_REPL_CONNECT;
491
+ redisLog(REDIS_NOTICE,"SLAVE OF %s:%d enabled (user request)",
492
+ server.masterhost, server.masterport);
493
+ }
494
+ addReply(c,shared.ok);
495
+ }
496
+
497
+ /* --------------------------- REPLICATION CRON ---------------------------- */
498
+
499
+ #define REDIS_REPL_TIMEOUT 60
500
+ #define REDIS_REPL_PING_SLAVE_PERIOD 10
501
+
502
+ void replicationCron(void) {
503
+ /* Bulk transfer I/O timeout? */
504
+ if (server.masterhost && server.replstate == REDIS_REPL_TRANSFER &&
505
+ (time(NULL)-server.repl_transfer_lastio) > REDIS_REPL_TIMEOUT)
506
+ {
507
+ redisLog(REDIS_WARNING,"Timeout receiving bulk data from MASTER...");
508
+ replicationAbortSyncTransfer();
509
+ }
510
+
511
+ /* Timed out master when we are an already connected slave? */
512
+ if (server.masterhost && server.replstate == REDIS_REPL_CONNECTED &&
513
+ (time(NULL)-server.master->lastinteraction) > REDIS_REPL_TIMEOUT)
514
+ {
515
+ redisLog(REDIS_WARNING,"MASTER time out: no data nor PING received...");
516
+ freeClient(server.master);
517
+ }
518
+
519
+ /* Check if we should connect to a MASTER */
520
+ if (server.replstate == REDIS_REPL_CONNECT) {
521
+ redisLog(REDIS_NOTICE,"Connecting to MASTER...");
522
+ if (syncWithMaster() == REDIS_OK) {
523
+ redisLog(REDIS_NOTICE,"MASTER <-> SLAVE sync started: SYNC sent");
524
+ }
525
+ }
526
+
527
+ /* If we have attached slaves, PING them from time to time.
528
+ * So slaves can implement an explicit timeout to masters, and will
529
+ * be able to detect a link disconnection even if the TCP connection
530
+ * will not actually go down. */
531
+ if (!(server.cronloops % (REDIS_REPL_PING_SLAVE_PERIOD*10))) {
532
+ listIter li;
533
+ listNode *ln;
534
+
535
+ listRewind(server.slaves,&li);
536
+ while((ln = listNext(&li))) {
537
+ redisClient *slave = ln->value;
538
+
539
+ /* Don't ping slaves that are in the middle of a bulk transfer
540
+ * with the master for first synchronization. */
541
+ if (slave->replstate == REDIS_REPL_SEND_BULK) continue;
542
+ if (slave->replstate == REDIS_REPL_ONLINE) {
543
+ /* If the slave is online send a normal ping */
544
+ addReplySds(slave,sdsnew("PING\r\n"));
545
+ } else {
546
+ /* Otherwise we are in the pre-synchronization stage.
547
+ * Just a newline will do the work of refreshing the
548
+ * connection last interaction time, and at the same time
549
+ * we'll be sure that being a single char there are no
550
+ * short-write problems. */
551
+ if (write(slave->fd, "\n", 1) == -1) {
552
+ /* Don't worry, it's just a ping. */
553
+ }
554
+ }
555
+ }
556
+ }
557
+ }