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.
- data/LICENSE +38 -0
- data/README.md +33 -0
- data/bin/redis +114 -0
- data/redis/Makefile +5 -0
- data/redis/extconf.rb +3 -0
- data/redis/redis-2.2.11/00-RELEASENOTES +199 -0
- data/redis/redis-2.2.11/BUGS +1 -0
- data/redis/redis-2.2.11/CONTRIBUTING +13 -0
- data/redis/redis-2.2.11/COPYING +10 -0
- data/redis/redis-2.2.11/Changelog +1032 -0
- data/redis/redis-2.2.11/INSTALL +30 -0
- data/redis/redis-2.2.11/Makefile +22 -0
- data/redis/redis-2.2.11/README +83 -0
- data/redis/redis-2.2.11/TODO +4 -0
- data/redis/redis-2.2.11/client-libraries/README +11 -0
- data/redis/redis-2.2.11/deps/hiredis/COPYING +10 -0
- data/redis/redis-2.2.11/deps/hiredis/Makefile +115 -0
- data/redis/redis-2.2.11/deps/hiredis/README.md +311 -0
- data/redis/redis-2.2.11/deps/hiredis/TODO +2 -0
- data/redis/redis-2.2.11/deps/hiredis/adapters/ae.h +95 -0
- data/redis/redis-2.2.11/deps/hiredis/adapters/libev.h +113 -0
- data/redis/redis-2.2.11/deps/hiredis/adapters/libevent.h +76 -0
- data/redis/redis-2.2.11/deps/hiredis/async.c +321 -0
- data/redis/redis-2.2.11/deps/hiredis/async.h +112 -0
- data/redis/redis-2.2.11/deps/hiredis/example-ae.c +53 -0
- data/redis/redis-2.2.11/deps/hiredis/example-libev.c +47 -0
- data/redis/redis-2.2.11/deps/hiredis/example-libevent.c +48 -0
- data/redis/redis-2.2.11/deps/hiredis/example.c +67 -0
- data/redis/redis-2.2.11/deps/hiredis/fmacros.h +15 -0
- data/redis/redis-2.2.11/deps/hiredis/hiredis.c +1058 -0
- data/redis/redis-2.2.11/deps/hiredis/hiredis.h +170 -0
- data/redis/redis-2.2.11/deps/hiredis/net.c +170 -0
- data/redis/redis-2.2.11/deps/hiredis/net.h +43 -0
- data/redis/redis-2.2.11/deps/hiredis/sds.c +479 -0
- data/redis/redis-2.2.11/deps/hiredis/sds.h +77 -0
- data/redis/redis-2.2.11/deps/hiredis/test.c +479 -0
- data/redis/redis-2.2.11/deps/hiredis/util.h +40 -0
- data/redis/redis-2.2.11/deps/linenoise/Makefile +10 -0
- data/redis/redis-2.2.11/deps/linenoise/README.markdown +45 -0
- data/redis/redis-2.2.11/deps/linenoise/example.c +27 -0
- data/redis/redis-2.2.11/deps/linenoise/linenoise.c +609 -0
- data/redis/redis-2.2.11/deps/linenoise/linenoise.h +55 -0
- data/redis/redis-2.2.11/design-documents/REDIS-CLUSTER +214 -0
- data/redis/redis-2.2.11/design-documents/REDIS-CLUSTER-2 +343 -0
- data/redis/redis-2.2.11/doc/AppendCommand.html +48 -0
- data/redis/redis-2.2.11/doc/AppendOnlyFileHowto.html +41 -0
- data/redis/redis-2.2.11/doc/AuthCommand.html +39 -0
- data/redis/redis-2.2.11/doc/Benchmarks.html +129 -0
- data/redis/redis-2.2.11/doc/BgrewriteaofCommand.html +41 -0
- data/redis/redis-2.2.11/doc/BgsaveCommand.html +39 -0
- data/redis/redis-2.2.11/doc/BlpopCommand.html +51 -0
- data/redis/redis-2.2.11/doc/BrpoplpushCommand.html +39 -0
- data/redis/redis-2.2.11/doc/CommandReference.html +47 -0
- data/redis/redis-2.2.11/doc/Comparisons.html +42 -0
- data/redis/redis-2.2.11/doc/ConfigCommand.html +76 -0
- data/redis/redis-2.2.11/doc/Configuration.html +38 -0
- data/redis/redis-2.2.11/doc/ConnectionHandlingSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/ControlCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/Credits.html +38 -0
- data/redis/redis-2.2.11/doc/DbsizeCommand.html +38 -0
- data/redis/redis-2.2.11/doc/DelCommand.html +41 -0
- data/redis/redis-2.2.11/doc/DesignPatterns.html +37 -0
- data/redis/redis-2.2.11/doc/EventLibray.html +44 -0
- data/redis/redis-2.2.11/doc/ExistsCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ExpireCommand.html +96 -0
- data/redis/redis-2.2.11/doc/FAQ.html +70 -0
- data/redis/redis-2.2.11/doc/Features.html +38 -0
- data/redis/redis-2.2.11/doc/FlushallCommand.html +39 -0
- data/redis/redis-2.2.11/doc/FlushdbCommand.html +39 -0
- data/redis/redis-2.2.11/doc/FromSqlToDataStructures.html +37 -0
- data/redis/redis-2.2.11/doc/GenericCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/GetCommand.html +39 -0
- data/redis/redis-2.2.11/doc/GetbitCommand.html +39 -0
- data/redis/redis-2.2.11/doc/GetsetCommand.html +38 -0
- data/redis/redis-2.2.11/doc/HackingStrings.html +83 -0
- data/redis/redis-2.2.11/doc/HashCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/Hashes.html +37 -0
- data/redis/redis-2.2.11/doc/HdelCommand.html +39 -0
- data/redis/redis-2.2.11/doc/HexistsCommand.html +39 -0
- data/redis/redis-2.2.11/doc/HgetCommand.html +39 -0
- data/redis/redis-2.2.11/doc/HgetallCommand.html +40 -0
- data/redis/redis-2.2.11/doc/HincrbyCommand.html +45 -0
- data/redis/redis-2.2.11/doc/HlenCommand.html +38 -0
- data/redis/redis-2.2.11/doc/HmgetCommand.html +40 -0
- data/redis/redis-2.2.11/doc/HmsetCommand.html +40 -0
- data/redis/redis-2.2.11/doc/HsetCommand.html +40 -0
- data/redis/redis-2.2.11/doc/HsetnxCommand.html +41 -0
- data/redis/redis-2.2.11/doc/IncrCommand.html +43 -0
- data/redis/redis-2.2.11/doc/InfoCommand.html +48 -0
- data/redis/redis-2.2.11/doc/IntroductionToRedisDataTypes.html +152 -0
- data/redis/redis-2.2.11/doc/KeysCommand.html +43 -0
- data/redis/redis-2.2.11/doc/LastsaveCommand.html +39 -0
- data/redis/redis-2.2.11/doc/LindexCommand.html +40 -0
- data/redis/redis-2.2.11/doc/ListCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/Lists.html +42 -0
- data/redis/redis-2.2.11/doc/LlenCommand.html +41 -0
- data/redis/redis-2.2.11/doc/LpopCommand.html +41 -0
- data/redis/redis-2.2.11/doc/LrangeCommand.html +47 -0
- data/redis/redis-2.2.11/doc/LremCommand.html +41 -0
- data/redis/redis-2.2.11/doc/LsetCommand.html +38 -0
- data/redis/redis-2.2.11/doc/LtrimCommand.html +47 -0
- data/redis/redis-2.2.11/doc/MgetCommand.html +52 -0
- data/redis/redis-2.2.11/doc/MonitorCommand.html +63 -0
- data/redis/redis-2.2.11/doc/MoveCommand.html +42 -0
- data/redis/redis-2.2.11/doc/MsetCommand.html +44 -0
- data/redis/redis-2.2.11/doc/MultiExecCommand.html +166 -0
- data/redis/redis-2.2.11/doc/NonexistentCommands.html +51 -0
- data/redis/redis-2.2.11/doc/ObjectHashMappers.html +39 -0
- data/redis/redis-2.2.11/doc/Pipelining.html +36 -0
- data/redis/redis-2.2.11/doc/ProgrammingExamples.html +38 -0
- data/redis/redis-2.2.11/doc/ProtocolSpecification.html +137 -0
- data/redis/redis-2.2.11/doc/PublishSubscribe.html +115 -0
- data/redis/redis-2.2.11/doc/QuickStart.html +68 -0
- data/redis/redis-2.2.11/doc/QuitCommand.html +38 -0
- data/redis/redis-2.2.11/doc/README.html +119 -0
- data/redis/redis-2.2.11/doc/RandomkeyCommand.html +39 -0
- data/redis/redis-2.2.11/doc/Redis0100ChangeLog.html +67 -0
- data/redis/redis-2.2.11/doc/Redis0900ChangeLog.html +56 -0
- data/redis/redis-2.2.11/doc/RedisBigData.html +61 -0
- data/redis/redis-2.2.11/doc/RedisCLI.html +37 -0
- data/redis/redis-2.2.11/doc/RedisEventLibrary.html +70 -0
- data/redis/redis-2.2.11/doc/RedisGuides.html +37 -0
- data/redis/redis-2.2.11/doc/RedisInternals.html +38 -0
- data/redis/redis-2.2.11/doc/RedisPipelining.html +93 -0
- data/redis/redis-2.2.11/doc/RedisStatus.html +56 -0
- data/redis/redis-2.2.11/doc/Redis_1_2_0_Changelog.html +40 -0
- data/redis/redis-2.2.11/doc/Redis_2_0_0_Changelog.html +62 -0
- data/redis/redis-2.2.11/doc/Redis_2_0_Whats_new.html +59 -0
- data/redis/redis-2.2.11/doc/RenameCommand.html +39 -0
- data/redis/redis-2.2.11/doc/RenamenxCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ReplicationHowto.html +43 -0
- data/redis/redis-2.2.11/doc/ReplyTypes.html +42 -0
- data/redis/redis-2.2.11/doc/RoadMap.html +38 -0
- data/redis/redis-2.2.11/doc/RpoplpushCommand.html +44 -0
- data/redis/redis-2.2.11/doc/RpushCommand.html +40 -0
- data/redis/redis-2.2.11/doc/SaddCommand.html +41 -0
- data/redis/redis-2.2.11/doc/SaveCommand.html +39 -0
- data/redis/redis-2.2.11/doc/ScardCommand.html +41 -0
- data/redis/redis-2.2.11/doc/SdiffCommand.html +45 -0
- data/redis/redis-2.2.11/doc/SdiffstoreCommand.html +38 -0
- data/redis/redis-2.2.11/doc/SelectCommand.html +39 -0
- data/redis/redis-2.2.11/doc/SetCommand.html +39 -0
- data/redis/redis-2.2.11/doc/SetCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/SetbitCommand.html +45 -0
- data/redis/redis-2.2.11/doc/SetexCommand.html +42 -0
- data/redis/redis-2.2.11/doc/SetnxCommand.html +51 -0
- data/redis/redis-2.2.11/doc/SetrangeCommand.html +58 -0
- data/redis/redis-2.2.11/doc/Sets.html +36 -0
- data/redis/redis-2.2.11/doc/ShutdownCommand.html +39 -0
- data/redis/redis-2.2.11/doc/SideBar.html +36 -0
- data/redis/redis-2.2.11/doc/SinterCommand.html +40 -0
- data/redis/redis-2.2.11/doc/SinterstoreCommand.html +39 -0
- data/redis/redis-2.2.11/doc/SismemberCommand.html +42 -0
- data/redis/redis-2.2.11/doc/SlaveofCommand.html +41 -0
- data/redis/redis-2.2.11/doc/SmembersCommand.html +38 -0
- data/redis/redis-2.2.11/doc/SmoveCommand.html +44 -0
- data/redis/redis-2.2.11/doc/SortCommand.html +75 -0
- data/redis/redis-2.2.11/doc/SortedSetCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/SortedSets.html +36 -0
- data/redis/redis-2.2.11/doc/Speed.html +38 -0
- data/redis/redis-2.2.11/doc/SponsorshipHistory.html +38 -0
- data/redis/redis-2.2.11/doc/SpopCommand.html +40 -0
- data/redis/redis-2.2.11/doc/SrandmemberCommand.html +40 -0
- data/redis/redis-2.2.11/doc/SremCommand.html +42 -0
- data/redis/redis-2.2.11/doc/StringCommandsSidebar.html +36 -0
- data/redis/redis-2.2.11/doc/Strings.html +37 -0
- data/redis/redis-2.2.11/doc/StrlenCommand.html +39 -0
- data/redis/redis-2.2.11/doc/SubstrCommand.html +52 -0
- data/redis/redis-2.2.11/doc/SunionCommand.html +40 -0
- data/redis/redis-2.2.11/doc/SunionstoreCommand.html +38 -0
- data/redis/redis-2.2.11/doc/SupportedLanguages.html +60 -0
- data/redis/redis-2.2.11/doc/SupportedPlatforms.html +37 -0
- data/redis/redis-2.2.11/doc/TemplateCommand.html +38 -0
- data/redis/redis-2.2.11/doc/TtlCommand.html +38 -0
- data/redis/redis-2.2.11/doc/TwitterAlikeExample.html +250 -0
- data/redis/redis-2.2.11/doc/TypeCommand.html +46 -0
- data/redis/redis-2.2.11/doc/UnstableSource.html +39 -0
- data/redis/redis-2.2.11/doc/VirtualMemorySpecification.html +156 -0
- data/redis/redis-2.2.11/doc/VirtualMemoryUserGuide.html +66 -0
- data/redis/redis-2.2.11/doc/ZaddCommand.html +43 -0
- data/redis/redis-2.2.11/doc/ZcardCommand.html +41 -0
- data/redis/redis-2.2.11/doc/ZincrbyCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ZrangeCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ZrangebyscoreCommand.html +77 -0
- data/redis/redis-2.2.11/doc/ZrankCommand.html +43 -0
- data/redis/redis-2.2.11/doc/ZremCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ZremrangebyrankCommand.html +39 -0
- data/redis/redis-2.2.11/doc/ZremrangebyscoreCommand.html +39 -0
- data/redis/redis-2.2.11/doc/ZscoreCommand.html +41 -0
- data/redis/redis-2.2.11/doc/ZunionCommand.html +42 -0
- data/redis/redis-2.2.11/doc/ZunionstoreCommand.html +43 -0
- data/redis/redis-2.2.11/doc/index.html +43 -0
- data/redis/redis-2.2.11/doc/redis.png +0 -0
- data/redis/redis-2.2.11/doc/style.css +25 -0
- data/redis/redis-2.2.11/redis.conf +417 -0
- data/redis/redis-2.2.11/src/Makefile +177 -0
- data/redis/redis-2.2.11/src/adlist.c +325 -0
- data/redis/redis-2.2.11/src/adlist.h +92 -0
- data/redis/redis-2.2.11/src/ae.c +390 -0
- data/redis/redis-2.2.11/src/ae.h +117 -0
- data/redis/redis-2.2.11/src/ae_epoll.c +91 -0
- data/redis/redis-2.2.11/src/ae_kqueue.c +93 -0
- data/redis/redis-2.2.11/src/ae_select.c +72 -0
- data/redis/redis-2.2.11/src/anet.c +347 -0
- data/redis/redis-2.2.11/src/anet.h +57 -0
- data/redis/redis-2.2.11/src/aof.c +675 -0
- data/redis/redis-2.2.11/src/config.c +627 -0
- data/redis/redis-2.2.11/src/config.h +64 -0
- data/redis/redis-2.2.11/src/db.c +543 -0
- data/redis/redis-2.2.11/src/debug.c +314 -0
- data/redis/redis-2.2.11/src/dict.c +721 -0
- data/redis/redis-2.2.11/src/dict.h +156 -0
- data/redis/redis-2.2.11/src/fmacros.h +15 -0
- data/redis/redis-2.2.11/src/help.h +638 -0
- data/redis/redis-2.2.11/src/intset.c +422 -0
- data/redis/redis-2.2.11/src/intset.h +19 -0
- data/redis/redis-2.2.11/src/lzf.h +100 -0
- data/redis/redis-2.2.11/src/lzfP.h +159 -0
- data/redis/redis-2.2.11/src/lzf_c.c +295 -0
- data/redis/redis-2.2.11/src/lzf_d.c +150 -0
- data/redis/redis-2.2.11/src/mkreleasehdr.sh +9 -0
- data/redis/redis-2.2.11/src/multi.c +268 -0
- data/redis/redis-2.2.11/src/networking.c +899 -0
- data/redis/redis-2.2.11/src/object.c +484 -0
- data/redis/redis-2.2.11/src/pqsort.c +197 -0
- data/redis/redis-2.2.11/src/pqsort.h +15 -0
- data/redis/redis-2.2.11/src/pubsub.c +267 -0
- data/redis/redis-2.2.11/src/rdb.c +1020 -0
- data/redis/redis-2.2.11/src/redis-benchmark.c +530 -0
- data/redis/redis-2.2.11/src/redis-check-aof.c +185 -0
- data/redis/redis-2.2.11/src/redis-check-dump.c +681 -0
- data/redis/redis-2.2.11/src/redis-cli.c +773 -0
- data/redis/redis-2.2.11/src/redis.c +1677 -0
- data/redis/redis-2.2.11/src/redis.h +1022 -0
- data/redis/redis-2.2.11/src/release.c +13 -0
- data/redis/redis-2.2.11/src/replication.c +557 -0
- data/redis/redis-2.2.11/src/sds.c +639 -0
- data/redis/redis-2.2.11/src/sds.h +78 -0
- data/redis/redis-2.2.11/src/sha1.c +276 -0
- data/redis/redis-2.2.11/src/sha1.h +17 -0
- data/redis/redis-2.2.11/src/solarisfixes.h +22 -0
- data/redis/redis-2.2.11/src/sort.c +389 -0
- data/redis/redis-2.2.11/src/syncio.c +154 -0
- data/redis/redis-2.2.11/src/t_hash.c +476 -0
- data/redis/redis-2.2.11/src/t_list.c +986 -0
- data/redis/redis-2.2.11/src/t_set.c +610 -0
- data/redis/redis-2.2.11/src/t_string.c +438 -0
- data/redis/redis-2.2.11/src/t_zset.c +1084 -0
- data/redis/redis-2.2.11/src/testhelp.h +54 -0
- data/redis/redis-2.2.11/src/util.c +243 -0
- data/redis/redis-2.2.11/src/valgrind.sup +5 -0
- data/redis/redis-2.2.11/src/version.h +1 -0
- data/redis/redis-2.2.11/src/vm.c +1149 -0
- data/redis/redis-2.2.11/src/ziplist.c +1323 -0
- data/redis/redis-2.2.11/src/ziplist.h +15 -0
- data/redis/redis-2.2.11/src/zipmap.c +455 -0
- data/redis/redis-2.2.11/src/zipmap.h +48 -0
- data/redis/redis-2.2.11/src/zmalloc.c +278 -0
- data/redis/redis-2.2.11/src/zmalloc.h +47 -0
- data/redis/redis-2.2.11/tests/assets/default.conf +308 -0
- data/redis/redis-2.2.11/tests/integration/aof.tcl +104 -0
- data/redis/redis-2.2.11/tests/integration/redis-cli.tcl +208 -0
- data/redis/redis-2.2.11/tests/integration/replication.tcl +98 -0
- data/redis/redis-2.2.11/tests/support/redis.tcl +241 -0
- data/redis/redis-2.2.11/tests/support/server.tcl +294 -0
- data/redis/redis-2.2.11/tests/support/test.tcl +190 -0
- data/redis/redis-2.2.11/tests/support/tmpfile.tcl +15 -0
- data/redis/redis-2.2.11/tests/support/util.tcl +296 -0
- data/redis/redis-2.2.11/tests/test_helper.tcl +221 -0
- data/redis/redis-2.2.11/tests/unit/auth.tcl +15 -0
- data/redis/redis-2.2.11/tests/unit/basic.tcl +616 -0
- data/redis/redis-2.2.11/tests/unit/cas.tcl +135 -0
- data/redis/redis-2.2.11/tests/unit/expire.tcl +74 -0
- data/redis/redis-2.2.11/tests/unit/other.tcl +240 -0
- data/redis/redis-2.2.11/tests/unit/printver.tcl +6 -0
- data/redis/redis-2.2.11/tests/unit/protocol.tcl +62 -0
- data/redis/redis-2.2.11/tests/unit/pubsub.tcl +195 -0
- data/redis/redis-2.2.11/tests/unit/quit.tcl +40 -0
- data/redis/redis-2.2.11/tests/unit/sort.tcl +189 -0
- data/redis/redis-2.2.11/tests/unit/type/hash.tcl +300 -0
- data/redis/redis-2.2.11/tests/unit/type/list.tcl +819 -0
- data/redis/redis-2.2.11/tests/unit/type/set.tcl +334 -0
- data/redis/redis-2.2.11/tests/unit/type/zset.tcl +587 -0
- data/redis/redis-2.2.11/utils/build-static-symbols.tcl +22 -0
- data/redis/redis-2.2.11/utils/generate-command-help.rb +112 -0
- data/redis/redis-2.2.11/utils/mktarball.sh +13 -0
- data/redis/redis-2.2.11/utils/redis-copy.rb +78 -0
- data/redis/redis-2.2.11/utils/redis-sha1.rb +52 -0
- data/redis/redis-2.2.11/utils/redis_init_script +42 -0
- metadata +362 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
To compile Redis, do the following:
|
2
|
+
|
3
|
+
cd src; make
|
4
|
+
|
5
|
+
The compilation will produce a redis-server binary.
|
6
|
+
|
7
|
+
To install Redis, use
|
8
|
+
|
9
|
+
make install
|
10
|
+
|
11
|
+
and all the binaries will be installed on /usr/local/bin.
|
12
|
+
|
13
|
+
Alternatively:
|
14
|
+
|
15
|
+
make PREFIX=/some/other/directory
|
16
|
+
|
17
|
+
to have the binaries in /some/other/directory/bin.
|
18
|
+
|
19
|
+
Run the server using the following command line:
|
20
|
+
|
21
|
+
/path/to/redis-server
|
22
|
+
|
23
|
+
This will start a Redis server with the default configuration.
|
24
|
+
|
25
|
+
Otherwise if you want to provide your configuration use:
|
26
|
+
|
27
|
+
/path/to/redis-server /path/to/redis.conf
|
28
|
+
|
29
|
+
You can find an example redis.conf file in the root directory
|
30
|
+
of this source distribution.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Top level makefile, the real shit is at src/Makefile
|
2
|
+
|
3
|
+
TARGETS=32bit noopt test
|
4
|
+
|
5
|
+
all:
|
6
|
+
cd src && $(MAKE) $@
|
7
|
+
|
8
|
+
install: dummy
|
9
|
+
cd src && $(MAKE) $@
|
10
|
+
|
11
|
+
clean:
|
12
|
+
cd src && $(MAKE) $@
|
13
|
+
cd deps/hiredis && $(MAKE) $@
|
14
|
+
cd deps/linenoise && $(MAKE) $@
|
15
|
+
|
16
|
+
$(TARGETS):
|
17
|
+
cd src && $(MAKE) $@
|
18
|
+
|
19
|
+
src/help.h:
|
20
|
+
@./utils/generate-command-help.rb > $@
|
21
|
+
|
22
|
+
dummy:
|
@@ -0,0 +1,83 @@
|
|
1
|
+
Where to find complete Redis documentation?
|
2
|
+
-------------------------------------------
|
3
|
+
|
4
|
+
This README is just a fast "quick start" document. You can find more detailed
|
5
|
+
documentation at http://redis.io
|
6
|
+
|
7
|
+
Building Redis
|
8
|
+
--------------
|
9
|
+
|
10
|
+
It is as simple as:
|
11
|
+
|
12
|
+
% make
|
13
|
+
|
14
|
+
Redis is just a single binary, but if you want to install it you can use
|
15
|
+
the "make install" target that will copy the binary in /usr/local/bin
|
16
|
+
for default. You can also use "make PREFIX=/some/other/directory install"
|
17
|
+
if you wish to use a different destination.
|
18
|
+
|
19
|
+
You can run a 32 bit Redis binary using:
|
20
|
+
|
21
|
+
% make 32bit
|
22
|
+
|
23
|
+
After building Redis is a good idea to test it, using:
|
24
|
+
|
25
|
+
% make test
|
26
|
+
|
27
|
+
Buliding using tcmalloc
|
28
|
+
-----------------------
|
29
|
+
|
30
|
+
tcmalloc is a fast and space efficient implementation (for little objects)
|
31
|
+
of malloc(). Compiling Redis with it can improve performances and memeory
|
32
|
+
usage. You can read more about it here:
|
33
|
+
|
34
|
+
http://goog-perftools.sourceforge.net/doc/tcmalloc.html
|
35
|
+
|
36
|
+
In order to compile Redis with tcmalloc support install tcmalloc on your system
|
37
|
+
and then use:
|
38
|
+
|
39
|
+
% make USE_TCMALLOC=yes
|
40
|
+
|
41
|
+
Note that you can pass any other target to make, as long as you append
|
42
|
+
USE_TCMALLOC=yes at the end.
|
43
|
+
|
44
|
+
Running Redis
|
45
|
+
-------------
|
46
|
+
|
47
|
+
To run Redis with the default configuration just type:
|
48
|
+
|
49
|
+
% cd src
|
50
|
+
% ./redis-server
|
51
|
+
|
52
|
+
If you want to provide your redis.conf, you have to run it using an additional
|
53
|
+
parameter (the path of the configuration file):
|
54
|
+
|
55
|
+
% cd src
|
56
|
+
% ./redis-server /path/to/redis.conf
|
57
|
+
|
58
|
+
Playing with Redis
|
59
|
+
------------------
|
60
|
+
|
61
|
+
You can use redis-cli to play with Redis. Start a redis-server instance,
|
62
|
+
then in another terminal try the following:
|
63
|
+
|
64
|
+
% cd src
|
65
|
+
% ./redis-cli
|
66
|
+
redis> ping
|
67
|
+
PONG
|
68
|
+
redis> set foo bar
|
69
|
+
OK
|
70
|
+
redis> get foo
|
71
|
+
"bar"
|
72
|
+
redis> incr mycounter
|
73
|
+
(integer) 1
|
74
|
+
redis> incr mycounter
|
75
|
+
(integer) 2
|
76
|
+
redis>
|
77
|
+
|
78
|
+
You can find the list of all the available commands here:
|
79
|
+
|
80
|
+
http://redis.io/commands
|
81
|
+
|
82
|
+
Enjoy!
|
83
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
An updated list of client libraries for Redis can be found here:
|
2
|
+
|
3
|
+
http://redis.io/clients
|
4
|
+
|
5
|
+
All the links are in the front page.
|
6
|
+
|
7
|
+
Most mainstream (and less mainstream) languages are supported.
|
8
|
+
|
9
|
+
If you plan to write a new client library for a missing language, please
|
10
|
+
get in touch with the other developers writing a message to the Redis google
|
11
|
+
group that is located here: http://groups.google.com/group/redis-db
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Copyright (c) 2006-2009, Salvatore Sanfilippo
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
7
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
8
|
+
* Neither the name of Redis nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
9
|
+
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# Hiredis Makefile
|
2
|
+
# Copyright (C) 2010 Salvatore Sanfilippo <antirez at gmail dot com>
|
3
|
+
# This file is released under the BSD license, see the COPYING file
|
4
|
+
|
5
|
+
OBJ = net.o hiredis.o sds.o async.o
|
6
|
+
BINS = hiredis-example hiredis-test
|
7
|
+
|
8
|
+
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
|
9
|
+
OPTIMIZATION?=-O3
|
10
|
+
ifeq ($(uname_S),SunOS)
|
11
|
+
CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -D__EXTENSIONS__ -D_XPG6 $(ARCH) $(PROF)
|
12
|
+
CCLINK?=-ldl -lnsl -lsocket -lm -lpthread
|
13
|
+
LDFLAGS?=-L. -Wl,-R,.
|
14
|
+
DYLIBNAME?=libhiredis.so
|
15
|
+
DYLIB_MAKE_CMD?=$(CC) -G -o ${DYLIBNAME} ${OBJ}
|
16
|
+
STLIBNAME?=libhiredis.a
|
17
|
+
STLIB_MAKE_CMD?=ar rcs ${STLIBNAME} ${OBJ}
|
18
|
+
else
|
19
|
+
ifeq ($(uname_S),Darwin)
|
20
|
+
CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -Wwrite-strings $(ARCH) $(PROF)
|
21
|
+
CCLINK?=-lm -pthread
|
22
|
+
LDFLAGS?=-L. -Wl,-rpath,.
|
23
|
+
OBJARCH?=-arch i386 -arch x86_64
|
24
|
+
DYLIBNAME?=libhiredis.dylib
|
25
|
+
DYLIB_MAKE_CMD?=libtool -dynamic -o ${DYLIBNAME} -lm ${DEBUG} - ${OBJ}
|
26
|
+
STLIBNAME?=libhiredis.a
|
27
|
+
STLIB_MAKE_CMD?=libtool -static -o ${STLIBNAME} - ${OBJ}
|
28
|
+
else
|
29
|
+
CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -Wwrite-strings $(ARCH) $(PROF)
|
30
|
+
CCLINK?=-lm -pthread
|
31
|
+
LDFLAGS?=-L. -Wl,-rpath,.
|
32
|
+
DYLIBNAME?=libhiredis.so
|
33
|
+
DYLIB_MAKE_CMD?=gcc -shared -Wl,-soname,${DYLIBNAME} -o ${DYLIBNAME} ${OBJ}
|
34
|
+
STLIBNAME?=libhiredis.a
|
35
|
+
STLIB_MAKE_CMD?=ar rcs ${STLIBNAME} ${OBJ}
|
36
|
+
endif
|
37
|
+
endif
|
38
|
+
|
39
|
+
CCOPT= $(CFLAGS) $(CCLINK)
|
40
|
+
DEBUG?= -g -ggdb
|
41
|
+
|
42
|
+
PREFIX?= /usr/local
|
43
|
+
INSTALL_INC= $(PREFIX)/include/hiredis
|
44
|
+
INSTALL_LIB= $(PREFIX)/lib
|
45
|
+
INSTALL= cp -a
|
46
|
+
|
47
|
+
all: ${DYLIBNAME} ${BINS}
|
48
|
+
|
49
|
+
# Deps (use make dep to generate this)
|
50
|
+
net.o: net.c fmacros.h net.h
|
51
|
+
async.o: async.c async.h hiredis.h sds.h util.h
|
52
|
+
example.o: example.c hiredis.h
|
53
|
+
hiredis.o: hiredis.c hiredis.h net.h sds.h util.h
|
54
|
+
sds.o: sds.c sds.h
|
55
|
+
test.o: test.c hiredis.h
|
56
|
+
|
57
|
+
${DYLIBNAME}: ${OBJ}
|
58
|
+
${DYLIB_MAKE_CMD}
|
59
|
+
|
60
|
+
${STLIBNAME}: ${OBJ}
|
61
|
+
${STLIB_MAKE_CMD}
|
62
|
+
|
63
|
+
dynamic: ${DYLIBNAME}
|
64
|
+
static: ${STLIBNAME}
|
65
|
+
|
66
|
+
# Binaries:
|
67
|
+
hiredis-example-libevent: example-libevent.c adapters/libevent.h ${DYLIBNAME}
|
68
|
+
$(CC) -o $@ $(CCOPT) $(DEBUG) $(LDFLAGS) -lhiredis -levent example-libevent.c
|
69
|
+
|
70
|
+
hiredis-example-libev: example-libev.c adapters/libev.h ${DYLIBNAME}
|
71
|
+
$(CC) -o $@ $(CCOPT) $(DEBUG) $(LDFLAGS) -lhiredis -lev example-libev.c
|
72
|
+
|
73
|
+
ifndef AE_DIR
|
74
|
+
hiredis-example-ae:
|
75
|
+
@echo "Please specify AE_DIR (e.g. <redis repository>/src)"
|
76
|
+
@false
|
77
|
+
else
|
78
|
+
hiredis-example-ae: example-ae.c adapters/ae.h ${DYLIBNAME}
|
79
|
+
$(CC) -o $@ $(CCOPT) $(DEBUG) -I$(AE_DIR) $(LDFLAGS) -lhiredis example-ae.c $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o
|
80
|
+
endif
|
81
|
+
|
82
|
+
hiredis-%: %.o ${DYLIBNAME}
|
83
|
+
$(CC) -o $@ $(CCOPT) $(DEBUG) $(LDFLAGS) -lhiredis $<
|
84
|
+
|
85
|
+
test: hiredis-test
|
86
|
+
./hiredis-test
|
87
|
+
|
88
|
+
.c.o:
|
89
|
+
$(CC) -c $(CFLAGS) $(OBJARCH) $(DEBUG) $(COMPILE_TIME) $<
|
90
|
+
|
91
|
+
clean:
|
92
|
+
rm -rf ${DYLIBNAME} ${STLIBNAME} $(BINS) hiredis-example* *.o *.gcda *.gcno *.gcov
|
93
|
+
|
94
|
+
dep:
|
95
|
+
$(CC) -MM *.c
|
96
|
+
|
97
|
+
install: ${DYLIBNAME} ${STLIBNAME}
|
98
|
+
mkdir -p $(INSTALL_INC) $(INSTALL_LIB)
|
99
|
+
$(INSTALL) hiredis.h async.h adapters $(INSTALL_INC)
|
100
|
+
$(INSTALL) ${DYLIBNAME} ${STLIBNAME} $(INSTALL_LIB)
|
101
|
+
|
102
|
+
32bit:
|
103
|
+
@echo ""
|
104
|
+
@echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
|
105
|
+
@echo ""
|
106
|
+
$(MAKE) ARCH="-m32"
|
107
|
+
|
108
|
+
gprof:
|
109
|
+
$(MAKE) PROF="-pg"
|
110
|
+
|
111
|
+
gcov:
|
112
|
+
$(MAKE) PROF="-fprofile-arcs -ftest-coverage"
|
113
|
+
|
114
|
+
noopt:
|
115
|
+
$(MAKE) OPTIMIZATION=""
|
@@ -0,0 +1,311 @@
|
|
1
|
+
# HIREDIS
|
2
|
+
|
3
|
+
Hiredis is a minimalistic C client library for the [Redis](http://redis.io/) database.
|
4
|
+
|
5
|
+
It is minimalistic because it just adds minimal support for the protocol, but
|
6
|
+
at the same time it uses an high level printf-alike API in order to make it
|
7
|
+
much higher level than otherwise suggested by its minimal code base and the
|
8
|
+
lack of explicit bindings for every Redis command.
|
9
|
+
|
10
|
+
Apart from supporting sending commands and receiving replies, it comes with
|
11
|
+
a reply parser that is decoupled from the I/O layer. It
|
12
|
+
is a stream parser designed for easy reusability, which can for instance be used
|
13
|
+
in higher level language bindings for efficient reply parsing.
|
14
|
+
|
15
|
+
Hiredis only supports the binary-safe Redis protocol, so you can use it with any
|
16
|
+
Redis version >= 1.2.0.
|
17
|
+
|
18
|
+
The library comes with multiple APIs. There is the
|
19
|
+
*synchronous API*, the *asynchronous API* and the *reply parsing API*.
|
20
|
+
|
21
|
+
## UPGRADING
|
22
|
+
|
23
|
+
Version 0.9.0 is a major overhaul of hiredis in every aspect. However, upgrading existing
|
24
|
+
code using hiredis should not be a big pain. The key thing to keep in mind when
|
25
|
+
upgrading is that hiredis >= 0.9.0 uses a `redisContext*` to keep state, in contrast to
|
26
|
+
the stateless 0.0.1 that only has a file descriptor to work with.
|
27
|
+
|
28
|
+
## Synchronous API
|
29
|
+
|
30
|
+
To consume the synchronous API, there are only a few function calls that need to be introduced:
|
31
|
+
|
32
|
+
redisContext *redisConnect(const char *ip, int port);
|
33
|
+
void *redisCommand(redisContext *c, const char *format, ...);
|
34
|
+
void freeReplyObject(void *reply);
|
35
|
+
|
36
|
+
### Connecting
|
37
|
+
|
38
|
+
The function `redisConnect` is used to create a so-called `redisContext`. The
|
39
|
+
context is where Hiredis holds state for a connection. The `redisContext`
|
40
|
+
struct has an integer `err` field that is non-zero when an the connection is in
|
41
|
+
an error state. The field `errstr` will contain a string with a description of
|
42
|
+
the error. More information on errors can be found in the **Errors** section.
|
43
|
+
After trying to connect to Redis using `redisConnect` you should
|
44
|
+
check the `err` field to see if establishing the connection was successful:
|
45
|
+
|
46
|
+
redisContext *c = redisConnect("127.0.0.1", 6379);
|
47
|
+
if (c->err) {
|
48
|
+
printf("Error: %s\n", c->errstr);
|
49
|
+
// handle error
|
50
|
+
}
|
51
|
+
|
52
|
+
### Sending commands
|
53
|
+
|
54
|
+
There are several ways to issue commands to Redis. The first that will be introduced is
|
55
|
+
`redisCommand`. This function takes a format similar to printf. In the simplest form,
|
56
|
+
it is used like this:
|
57
|
+
|
58
|
+
reply = redisCommand(context, "SET foo bar");
|
59
|
+
|
60
|
+
The specifier `%s` interpolates a string in the command, and uses `strlen` to
|
61
|
+
determine the length of the string:
|
62
|
+
|
63
|
+
reply = redisCommand(context, "SET foo %s", value);
|
64
|
+
|
65
|
+
When you need to pass binary safe strings in a command, the `%b` specifier can be
|
66
|
+
used. Together with a pointer to the string, it requires a `size_t` length argument
|
67
|
+
of the string:
|
68
|
+
|
69
|
+
reply = redisCommand(context, "SET foo %b", value, valuelen);
|
70
|
+
|
71
|
+
Internally, Hiredis splits the command in different arguments and will
|
72
|
+
convert it to the protocol used to communicate with Redis.
|
73
|
+
One or more spaces separates arguments, so you can use the specifiers
|
74
|
+
anywhere in an argument:
|
75
|
+
|
76
|
+
reply = redisCommand("SET key:%s %s", myid, value);
|
77
|
+
|
78
|
+
### Using replies
|
79
|
+
|
80
|
+
The return value of `redisCommand` holds a reply when the command was
|
81
|
+
successfully executed. When an error occurs, the return value is `NULL` and
|
82
|
+
the `err` field in the context will be set (see section on **Errors**).
|
83
|
+
Once an error is returned the context cannot be reused and you should set up
|
84
|
+
a new connection.
|
85
|
+
|
86
|
+
The standard replies that `redisCommand` are of the type `redisReply`. The
|
87
|
+
`type` field in the `redisReply` should be used to test what kind of reply
|
88
|
+
was received:
|
89
|
+
|
90
|
+
* **`REDIS_REPLY_STATUS`**:
|
91
|
+
* The command replied with a status reply. The status string can be accessed using `reply->str`.
|
92
|
+
The length of this string can be accessed using `reply->len`.
|
93
|
+
|
94
|
+
* **`REDIS_REPLY_ERROR`**:
|
95
|
+
* The command replied with an error. The error string can be accessed identical to `REDIS_REPLY_STATUS`.
|
96
|
+
|
97
|
+
* **`REDIS_REPLY_INTEGER`**:
|
98
|
+
* The command replied with an integer. The integer value can be accessed using the
|
99
|
+
`reply->integer` field of type `long long`.
|
100
|
+
|
101
|
+
* **`REDIS_REPLY_NIL`**:
|
102
|
+
* The command replied with a **nil** object. There is no data to access.
|
103
|
+
|
104
|
+
* **`REDIS_REPLY_STRING`**:
|
105
|
+
* A bulk (string) reply. The value of the reply can be accessed using `reply->str`.
|
106
|
+
The length of this string can be accessed using `reply->len`.
|
107
|
+
|
108
|
+
* **`REDIS_REPLY_ARRAY`**:
|
109
|
+
* A multi bulk reply. The number of elements in the multi bulk reply is stored in
|
110
|
+
`reply->elements`. Every element in the multi bulk reply is a `redisReply` object as well
|
111
|
+
and can be accessed via `reply->elements[..index..]`.
|
112
|
+
Redis may reply with nested arrays but this is fully supported.
|
113
|
+
|
114
|
+
Replies should be freed using the `freeReplyObject()` function.
|
115
|
+
Note that this function will take care of freeing sub-replies objects
|
116
|
+
contained in arrays and nested arrays, so there is no need for the user to
|
117
|
+
free the sub replies (it is actually harmful and will corrupt the memory).
|
118
|
+
|
119
|
+
### Cleaning up
|
120
|
+
|
121
|
+
To disconnect and free the context the following function can be used:
|
122
|
+
|
123
|
+
void redisFree(redisContext *c);
|
124
|
+
|
125
|
+
This function immediately closes the socket and then free's the allocations done in
|
126
|
+
creating the context.
|
127
|
+
|
128
|
+
### Sending commands (cont'd)
|
129
|
+
|
130
|
+
Together with `redisCommand`, the function `redisCommandArgv` can be used to issue commands.
|
131
|
+
It has the following prototype:
|
132
|
+
|
133
|
+
void *redisCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen);
|
134
|
+
|
135
|
+
It takes the number of arguments `argc`, an array of strings `argv` and the lengths of the
|
136
|
+
arguments `argvlen`. For convenience, `argvlen` may be set to `NULL` and the function will
|
137
|
+
use `strlen(3)` on every argument to determine its length. Obviously, when any of the arguments
|
138
|
+
need to be binary safe, the entire array of lengths `argvlen` should be provided.
|
139
|
+
|
140
|
+
The return value has the same semantic as `redisCommand`.
|
141
|
+
|
142
|
+
### Pipelining
|
143
|
+
|
144
|
+
To explain how Hiredis supports pipelining in a blocking connection, there needs to be
|
145
|
+
understanding of the internal execution flow.
|
146
|
+
|
147
|
+
When any of the functions in the `redisCommand` family is called, Hiredis first formats the
|
148
|
+
command according to the Redis protocol. The formatted command is then put in the output buffer
|
149
|
+
of the context. This output buffer is dynamic, so it can hold any number of commands.
|
150
|
+
After the command is put in the output buffer, `redisGetReply` is called. This function has the
|
151
|
+
following two execution paths:
|
152
|
+
|
153
|
+
1. The input buffer is non-empty:
|
154
|
+
* Try to parse a single reply from the input buffer and return it
|
155
|
+
* If no reply could be parsed, continue at *2*
|
156
|
+
2. The input buffer is empty:
|
157
|
+
* Write the **entire** output buffer to the socket
|
158
|
+
* Read from the socket until a single reply could be parsed
|
159
|
+
|
160
|
+
The function `redisGetReply` is exported as part of the Hiredis API and can be used when a reply
|
161
|
+
is expected on the socket. To pipeline commands, the only things that needs to be done is
|
162
|
+
filling up the output buffer. For this cause, two commands can be used that are identical
|
163
|
+
to the `redisCommand` family, apart from not returning a reply:
|
164
|
+
|
165
|
+
void redisAppendCommand(redisContext *c, const char *format, ...);
|
166
|
+
void redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen);
|
167
|
+
|
168
|
+
After calling either function one or more times, `redisGetReply` can be used to receive the
|
169
|
+
subsequent replies. The return value for this function is either `REDIS_OK` or `REDIS_ERR`, where
|
170
|
+
the latter means an error occurred while reading a reply. Just as with the other commands,
|
171
|
+
the `err` field in the context can be used to find out what the cause of this error is.
|
172
|
+
|
173
|
+
The following examples shows a simple pipeline (resulting in only a single call to `write(2)` and
|
174
|
+
a single call to `write(2)`):
|
175
|
+
|
176
|
+
redisReply *reply;
|
177
|
+
redisAppendCommand(context,"SET foo bar");
|
178
|
+
redisAppendCommand(context,"GET foo");
|
179
|
+
redisGetReply(context,&reply); // reply for SET
|
180
|
+
freeReplyObject(reply);
|
181
|
+
redisGetReply(context,&reply); // reply for GET
|
182
|
+
freeReplyObject(reply);
|
183
|
+
|
184
|
+
This API can also be used to implement a blocking subscriber:
|
185
|
+
|
186
|
+
reply = redisCommand(context,"SUBSCRIBE foo");
|
187
|
+
freeReplyObject(reply);
|
188
|
+
while(redisGetReply(context,&reply) == REDIS_OK) {
|
189
|
+
// consume message
|
190
|
+
freeReplyObject(reply);
|
191
|
+
}
|
192
|
+
|
193
|
+
### Errors
|
194
|
+
|
195
|
+
When a function call is not successful, depending on the function either `NULL` or `REDIS_ERR` is
|
196
|
+
returned. The `err` field inside the context will be non-zero and set to one of the
|
197
|
+
following constants:
|
198
|
+
|
199
|
+
* **`REDIS_ERR_IO`**:
|
200
|
+
There was an I/O error while creating the connection, trying to write
|
201
|
+
to the socket or read from the socket. If you included `errno.h` in your
|
202
|
+
application, you can use the global `errno` variable to find out what is
|
203
|
+
wrong.
|
204
|
+
|
205
|
+
* **`REDIS_ERR_EOF`**:
|
206
|
+
The server closed the connection which resulted in an empty read.
|
207
|
+
|
208
|
+
* **`REDIS_ERR_PROTOCOL`**:
|
209
|
+
There was an error while parsing the protocol.
|
210
|
+
|
211
|
+
* **`REDIS_ERR_OTHER`**:
|
212
|
+
Any other error. Currently, it is only used when a specified hostname to connect
|
213
|
+
to cannot be resolved.
|
214
|
+
|
215
|
+
In every case, the `errstr` field in the context will be set to hold a string representation
|
216
|
+
of the error.
|
217
|
+
|
218
|
+
## Asynchronous API
|
219
|
+
|
220
|
+
Hiredis comes with an asynchronous API that works easily with any event library.
|
221
|
+
Examples are bundled that show using Hiredis with [libev](http://software.schmorp.de/pkg/libev.html)
|
222
|
+
and [libevent](http://monkey.org/~provos/libevent/).
|
223
|
+
|
224
|
+
### Connecting
|
225
|
+
|
226
|
+
The function `redisAsyncConnect` can be used to establish a non-blocking connection to
|
227
|
+
Redis. It returns a pointer to the newly created `redisAsyncContext` struct. The `err` field
|
228
|
+
should be checked after creation to see if there were errors creating the connection.
|
229
|
+
Because the connection that will be created is non-blocking, the kernel is not able to
|
230
|
+
instantly return if the specified host and port is able to accept a connection.
|
231
|
+
|
232
|
+
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
|
233
|
+
if (c->err) {
|
234
|
+
printf("Error: %s\n", c->errstr);
|
235
|
+
// handle error
|
236
|
+
}
|
237
|
+
|
238
|
+
The asynchronous context can hold a disconnect callback function that is called when the
|
239
|
+
connection is disconnected (either because of an error or per user request). This function should
|
240
|
+
have the following prototype:
|
241
|
+
|
242
|
+
void(const redisAsyncContext *c, int status);
|
243
|
+
|
244
|
+
On a disconnect, the `status` argument is set to `REDIS_OK` when disconnection was initiated by the
|
245
|
+
user, or `REDIS_ERR` when the disconnection was caused by an error. When it is `REDIS_ERR`, the `err`
|
246
|
+
field in the context can be accessed to find out the cause of the error.
|
247
|
+
|
248
|
+
The context object is always free'd after the disconnect callback fired. When a reconnect is needed,
|
249
|
+
the disconnect callback is a good point to do so.
|
250
|
+
|
251
|
+
Setting the disconnect callback can only be done once per context. For subsequent calls it will
|
252
|
+
return `REDIS_ERR`. The function to set the disconnect callback has the following prototype:
|
253
|
+
|
254
|
+
int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn);
|
255
|
+
|
256
|
+
### Sending commands and their callbacks
|
257
|
+
|
258
|
+
In an asynchronous context, commands are automatically pipelined due to the nature of an event loop.
|
259
|
+
Therefore, unlike the synchronous API, there is only a single way to send commands.
|
260
|
+
Because commands are sent to Redis asynchronously, issuing a command requires a callback function
|
261
|
+
that is called when the reply is received. Reply callbacks should have the following prototype:
|
262
|
+
|
263
|
+
void(redisAsyncContext *c, void *reply, void *privdata);
|
264
|
+
|
265
|
+
The `privdata` argument can be used to curry arbitrary data to the callback from the point where
|
266
|
+
the command is initially queued for execution.
|
267
|
+
|
268
|
+
The functions that can be used to issue commands in an asynchronous context are:
|
269
|
+
|
270
|
+
int redisAsyncCommand(
|
271
|
+
redisAsyncContext *ac, redisCallbackFn *fn, void *privdata,
|
272
|
+
const char *format, ...);
|
273
|
+
int redisAsyncCommandArgv(
|
274
|
+
redisAsyncContext *ac, redisCallbackFn *fn, void *privdata,
|
275
|
+
int argc, const char **argv, const size_t *argvlen);
|
276
|
+
|
277
|
+
Both functions work like their blocking counterparts. The return value is `REDIS_OK` when the command
|
278
|
+
was successfully added to the output buffer and `REDIS_ERR` otherwise. Example: when the connection
|
279
|
+
is being disconnected per user-request, no new commands may be added to the output buffer and `REDIS_ERR` is
|
280
|
+
returned on calls to the `redisAsyncCommand` family.
|
281
|
+
|
282
|
+
If the reply for a command with a `NULL` callback is read, it is immediately free'd. When the callback
|
283
|
+
for a command is non-`NULL`, it is responsible for cleaning up the reply.
|
284
|
+
|
285
|
+
All pending callbacks are called with a `NULL` reply when the context encountered an error.
|
286
|
+
|
287
|
+
### Disconnecting
|
288
|
+
|
289
|
+
An asynchronous connection can be terminated using:
|
290
|
+
|
291
|
+
void redisAsyncDisconnect(redisAsyncContext *ac);
|
292
|
+
|
293
|
+
When this function is called, the connection is **not** immediately terminated. Instead, new
|
294
|
+
commands are no longer accepted and the connection is only terminated when all pending commands
|
295
|
+
have been written to the socket, their respective replies have been read and their respective
|
296
|
+
callbacks have been executed. After this, the disconnection callback is executed with the
|
297
|
+
`REDIS_OK` status and the context object is free'd.
|
298
|
+
|
299
|
+
### Hooking it up to event library *X*
|
300
|
+
|
301
|
+
There are a few hooks that need to be set on the context object after it is created.
|
302
|
+
See the `adapters/` directory for bindings to *libev* and *libevent*.
|
303
|
+
|
304
|
+
## Reply parsing API
|
305
|
+
|
306
|
+
To be done.
|
307
|
+
|
308
|
+
## AUTHORS
|
309
|
+
|
310
|
+
Hiredis was written by Salvatore Sanfilippo (antirez at gmail) and
|
311
|
+
Pieter Noordhuis (pcnoordhuis at gmail) and is released under the BSD license.
|