top

A simple client for connecting and interacting with redis.

To import inside your package do:

import "github.com/fzzy/radix/redis"

Connecting

Use either Dial or DialTimeout:

client, err := redis.Dial("tcp", "localhost:6379")
if err != nil {
	// handle err
}

Make sure to call Close on the client if you want to clean it up before the end of the program.

Cmd and Reply

The Cmd method returns a Reply, which has methods for converting to various types. Each of these methods returns an error which can either be a connection error (e.g. timeout), an application error (e.g. key is wrong type), or a conversion error (e.g. cannot convert to integer). You can also directly check the error using the Err field:

foo, err := client.Cmd("GET", "foo").Str()
if err != nil {
	// handle err
}

// Checking Err field directly

err = client.Cmd("SET", "foo", "bar", "EX", 3600).Err
if err != nil {
	// handle err
}

Multi Replies

The elements to Multi replies can be accessed as strings using List or ListBytes, or you can use the Elems field for more low-level access:

r := client.Cmd("MGET", "foo", "bar", "baz")

// This:
for _, elemStr := range r.List() {
	fmt.Println(elemStr)
}

// is equivalent to this:
for i := range r.Elems {
	elemStr, _ := r.Elems[i].Str()
	fmt.Println(elemStr)
}

Pipelining

Pipelining is when the client sends a bunch of commands to the server at once, and only once all the commands have been sent does it start reading the replies off the socket. This is supported using the Append and GetReply methods. Append will simply append the command to a buffer without sending it, the first time GetReply is called it will send all the commands in the buffer and return the Reply for the first command that was sent. Subsequent calls to GetReply return Replys for subsequent commands:

client.Append("GET", "foo")
client.Append("SET", "bar", "foo")
client.Append("DEL", "baz")

// Read GET foo reply
foo, err := client.GetReply().Str()
if err != nil {
	// handle err
}

// Read SET bar foo reply
if err := client.GetReply().Err; err != nil {
	// handle err
}

// Read DEL baz reply
if err := client.GetReply().Err; err != nil {
	// handle err
}

Imported by 257 package(s)

  1. github.com/Aishraj/gohort/shortener
  2. github.com/CenturyLinkLabs/dray/job
  3. github.com/Charlesworth/GoRedisVoter
  4. github.com/Charlesworth/sendgridMessageQue
  5. github.com/Diggs/go-one
  6. github.com/Doist/rqw/internal/rqw
  7. github.com/DuoSoftware/ARDS/ARDS/ArdsGo/ArdsRoutingEngine
  8. github.com/DuoSoftware/ARDS/ARDS/ArdsGo/HandlingAlgo
  9. github.com/DuoSoftware/ARDS/ARDS/ArdsGo/SelectionAlgo
  10. github.com/DuoSoftware/DVP-ARDSHandlingAlgorithm/HandlingAlgo
  11. github.com/DuoSoftware/DVP-ARDSLiteRoutingEngine/ArdsLiteRoutingEngine
  12. github.com/DuoSoftware/DVP-ARDSRoutingEngine/ArdsRoutingEngine
  13. github.com/DuoSoftware/DVP-ARDSSelectionAlgorithm/SelectionAlgo
  14. github.com/DuoSoftware/DVP-CallBackService/CallbackServer
  15. github.com/EOengineer/GoLang-Redis
  16. github.com/HenrySlawniak/imgd
  17. github.com/KNQ/kv/redisstore
  18. github.com/KevinPike/kaon
  19. github.com/LukeHandle/imgd
  20. github.com/Morsicus/GoRedy
  21. github.com/NuVivo314/stupid-proxy
  22. github.com/RUNDSP/radix/bench
  23. github.com/RUNDSP/radix/examples
  24. github.com/SamSaffron/redismux
  25. github.com/ShowMax/gogstash/output/redis
  26. github.com/SideCar6/aegis/aegis_redis
  27. github.com/SkyRocknRoll/gocrud/src
  28. github.com/SkyRocknRoll/gotry/src
  29. github.com/a-know/go-check-plugins/check-redis
  30. github.com/a-know/mackerel-agent-plugins/mackerel-plugin-redis
  31. github.com/abedra/craft-conf2016/workshop/processor/go
  32. github.com/agrafix/kvspeedlib
  33. github.com/aishraj/gohort/shortener
  34. github.com/alphagov/govuk_crawler_worker/ttl_hash_set
  35. github.com/alphagov/radix/bench
  36. github.com/alphagov/radix/examples
  37. github.com/alveary/overseer/registry
  38. github.com/amyangfei/redlock-go/redlock
  39. github.com/andrewtholt/ExploreGo
  40. github.com/atitsbest/temperature_service/handlers
  41. github.com/atitsbest/temperature_service/workers
  42. github.com/bdehamer/dray/job
  43. github.com/bdehamer/redis_list_demo/publisher
  44. github.com/bdehamer/redis_list_demo/subscriber
  45. github.com/benashford/redis-client-benchmarks/Go
  46. github.com/benwebber/envredis
  47. github.com/betamike/radix-extra/pool
  48. github.com/blockcypher/radix/bench
  49. github.com/blockcypher/radix/examples
  50. github.com/bluepeppers/redis-watcher
  51. github.com/bluestatedigital/flapjack-nagios-receiver
  52. github.com/brnstz/bus/internal/etc
  53. github.com/c4pt0r/jq
  54. github.com/carbonsrv/carbon/modules/middleware
  55. github.com/cghsystems/godata/health
  56. github.com/cghsystems/godata/record
  57. github.com/charlesworth/GoRedisVoter
  58. github.com/charlesworth/sendgridMessageQue
  59. github.com/chonglou/ksana
  60. github.com/chzyer-dev/radix/bench
  61. github.com/chzyer-dev/radix/examples
  62. github.com/citruspi/wintergarten/films
  63. github.com/colorsocean/stupid-proxy
  64. github.com/coseyo/radixpool
  65. github.com/craigfurman/gotoredis
  66. github.com/danslimmon/blitzer
  67. github.com/darkhelmet/ForrestFire/src/counter
  68. github.com/datastream/metrictools
  69. github.com/dgkang/radix/bench
  70. github.com/dgkang/radix/examples
  71. github.com/diggs/go-one
  72. github.com/diggs/gone
  73. github.com/dreamersdw/redis-view
  74. github.com/edvakf/freesozai
  75. github.com/essentialkaos/radix/bench
  76. github.com/essentialkaos/radix/examples
  77. github.com/evandigby/rtb/redis
  78. github.com/fancysupport/radix/bench
  79. github.com/fancysupport/radix/examples
  80. github.com/fbq/irc/irclog
  81. github.com/frodebjerke/beeroclock-api/redisclient
  82. github.com/frodetbj/beeroclock-api/redisclient
  83. github.com/fujin/tetragrammaton
  84. github.com/fujiwara/go-redis-setlock
  85. github.com/fzzy/radix/bench
  86. github.com/fzzy/radix/examples
  87. github.com/fzzy/radix/extra/cluster
  88. github.com/fzzy/radix/extra/pool
  89. github.com/fzzy/radix/extra/pubsub
  90. github.com/fzzy/radix/extra/sentinel
  91. github.com/gavincabbage/gbot/core
  92. github.com/gnagel/go-connection_pool/connection_pool/redis_connection_pool
  93. github.com/gnagel/go-redis_pool/redis_pool
  94. github.com/gpjt/stupid-proxy
  95. github.com/guregu/redsync.go/redsync
  96. github.com/hartfordfive/golog
  97. github.com/heydabop/yaircb
  98. github.com/hico-horiuchi/mackerel-agent-plugins/mackerel-plugin-redis
  99. github.com/hiroakis/go-check-plugins/check-redis
  100. github.com/hiroakis/mackerel-agent-plugins/mackerel-plugin-redis
  101. github.com/houst0n/gamekeeper/gamekeeper
  102. github.com/ian-lewis-cs/radix/bench
  103. github.com/ian-lewis-cs/radix/examples
  104. github.com/ivanabc/radix/bench
  105. github.com/ivanabc/radix/examples
  106. github.com/jansichermann/RedisFactory
  107. github.com/jansichermann/apiserver
  108. github.com/jansichermann/radix/bench
  109. github.com/jansichermann/radix/examples
  110. github.com/jansichermann/redisinterface
  111. github.com/jeremy-clerc/rediboard
  112. github.com/jimmysawczuk/norad/src/norad
  113. github.com/jonas747/fortia/rdb
  114. github.com/jonas747/yagpdb/automod
  115. github.com/jonas747/yagpdb/autorole
  116. github.com/jonas747/yagpdb/aylien
  117. github.com/jonas747/yagpdb/bot
  118. github.com/jonas747/yagpdb/commands
  119. github.com/jonas747/yagpdb/common
  120. github.com/jonas747/yagpdb/common/configstore
  121. github.com/jonas747/yagpdb/common/pubsub
  122. github.com/jonas747/yagpdb/customcommands
  123. github.com/jonas747/yagpdb/logs
  124. github.com/jonas747/yagpdb/moderation
  125. github.com/jonas747/yagpdb/notifications
  126. github.com/jonas747/yagpdb/reddit
  127. github.com/jonas747/yagpdb/reminders
  128. github.com/jonas747/yagpdb/reputation
  129. github.com/jonas747/yagpdb/serverstats
  130. github.com/jonas747/yagpdb/streaming
  131. github.com/jonas747/yagpdb/web
  132. github.com/josegonzalez/go-radixurl
  133. github.com/joshgarnett/sysminerd
  134. github.com/joshuarubin/radix/bench
  135. github.com/joshuarubin/radix/examples
  136. github.com/juhanoi/radix/bench
  137. github.com/juhanoi/radix/examples
  138. github.com/kairichard/zreqlo
  139. github.com/kevinpike/kaon
  140. github.com/kinghrothgar/gobin/storage/redis
  141. github.com/kinghrothgar/goblin/storage/redis
  142. github.com/kinghrothgar/redis/pool
  143. github.com/knq/kv/redisstore
  144. github.com/kuba--/yag/pkg/db
  145. github.com/laohanlinux/radix/bench
  146. github.com/laohanlinux/radix/examples
  147. github.com/laohanlinux/radix/extra/cluster
  148. github.com/laohanlinux/radix/extra/pubsub
  149. github.com/laohanlinux/radix/extra/sentinel
  150. github.com/laohanlinux/utils/kgredis
  151. github.com/leijou/crstats
  152. github.com/lovek323/btstat
  153. github.com/mackerelio/go-check-plugins/check-redis
  154. github.com/mackerelio/go-check-plugins/check-redis/lib
  155. github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-redis
  156. github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-redis/lib
  157. github.com/martin-naumann/go-hbcid/src/persistence
  158. github.com/mattkanwisher/microservices-book-code/redis
  159. github.com/mattkrea/go-sessions
  160. github.com/mblair/go-by-example/src
  161. github.com/mchmarny/go-counter
  162. github.com/mediocregopher/hyrax/server/storage/redis
  163. github.com/mediocregopher/swapgur/backend
  164. github.com/mgrigajtis/goqueue
  165. github.com/minotar/imgd
  166. github.com/miqui/dray/job
  167. github.com/msanterre/canoe
  168. github.com/najeira/mackerel-agent-plugins/mackerel-plugin-redis
  169. github.com/naokibtn/mackerel-agent-plugins/mackerel-plugin-redis
  170. github.com/ncodes/redlock-go/redlock
  171. github.com/niaquinto/Niq
  172. github.com/nicholaskh/redsync.go/redsync
  173. github.com/noahgoldman/dotaprofiles
  174. github.com/norisu0313/mackerel-agent-plugins/mackerel-plugin-redis
  175. github.com/nurblieh/restos/lib
  176. github.com/pandax381/mackerel-agent-plugins/mackerel-plugin-redis
  177. github.com/pelmers/autocompeter
  178. github.com/peterbe/autocompeter
  179. github.com/phamhongviet/slack-jobs
  180. github.com/phamhongviet/tadis
  181. github.com/phillihq/racoon/plugins/outputs/redis
  182. github.com/phillipCouto/activebrain
  183. github.com/praekelt/unicore-network/server
  184. github.com/projectarkc/psiphon/go/meek-server
  185. github.com/pyama86/mackerel-agent-plugins/mackerel-plugin-redis
  186. github.com/readmill/radix/bench
  187. github.com/readmill/radix/examples
  188. github.com/repsheet/repsheet
  189. github.com/repsheet/visualizer
  190. github.com/repsheet/warden
  191. github.com/richard-lyman/bob
  192. github.com/richardbowden/autocompeter
  193. github.com/richardhenry/go-pipeline/example
  194. github.com/rif/gocmd
  195. github.com/ritzalam/livemeeting
  196. github.com/rlayte/toystore/store/redis
  197. github.com/roeepolegfiverr/gofiverr/connectors
  198. github.com/saifabid/Redis-Golang-Testing
  199. github.com/saifabid/redisCommandTimer
  200. github.com/samalba/docker-cache
  201. github.com/samalba/hipache-go
  202. github.com/samora/ussd-go/sessionstores
  203. github.com/sanderhahn/kudoding
  204. github.com/saromanov/goredisbench
  205. github.com/saromanov/myexampledb
  206. github.com/shawnfeng/sutil/redispool
  207. github.com/shawnfeng/sutil/redispool/cache
  208. github.com/shokunin/ops_scripts/network
  209. github.com/shopsmart/autocompeter
  210. github.com/simonfuhrer/go-check-plugins/check-redis
  211. github.com/skyjia/radix/bench
  212. github.com/skyjia/radix/examples
  213. github.com/skyrocknroll/gocrud/src
  214. github.com/soma5mbaas/schemaworker
  215. github.com/souled3000/base/sentinels
  216. github.com/stanaka/go-check-plugins/check-redis
  217. github.com/stefanwille/redis-client-benchmarks/Go
  218. github.com/steventianhao/sslot/games
  219. github.com/steventianhao/sslot/web
  220. github.com/tclamb/redis/pool
  221. github.com/techslides/canoe
  222. github.com/tfzxyinhao/goStart
  223. github.com/tg/radix/bench
  224. github.com/tg/radix/examples
  225. github.com/theskyinflames/go-misc/com.theskyinflames.go.misc/lib_gc_cache/lib_gc_cache_source
  226. github.com/thomdixon/kaon/src
  227. github.com/tom--bo/mackerel-agent-plugins/mackerel-plugin-redis
  228. github.com/tsaikd/gogstash/output/redis
  229. github.com/tyler-sommer/squircy/squircy
  230. github.com/vashstorm/radix/bench
  231. github.com/vashstorm/radix/examples
  232. github.com/vashstorm/radix/extra/cluster
  233. github.com/vashstorm/radix/extra/pool
  234. github.com/vashstorm/radix/extra/pubsub
  235. github.com/vashstorm/radix/extra/sentinel
  236. github.com/vasilcovsky/microservices-book-code/redis
  237. github.com/vharitonsky/model_matcher
  238. github.com/vharitonsky/model_matcher/model_getter
  239. github.com/vharitonsky/push_server
  240. github.com/vharitonsky/radix/bench
  241. github.com/vharitonsky/radix/examples
  242. github.com/vharitonsky/radix/extra/pool
  243. github.com/vharitonsky/radix/extra/pubsub
  244. github.com/vharitonsky/radix/extra/sentinel
  245. github.com/vharitonsky/swarm
  246. github.com/vifino/carbon/modules/middleware
  247. github.com/waniji/mackerel-agent-plugins/mackerel-plugin-redis
  248. github.com/waniji/mackerel-agent-plugins/mackerel-plugin-redis/lib
  249. github.com/wolfems/fhback
  250. github.com/wowi42/GoLoadB/libgolb
  251. github.com/ygabo/canoe
  252. github.com/ymichael/sessions
  253. github.com/yoheimuta/go-check-plugins/check-redis
  254. github.com/yoheimuta/mackerel-agent-plugins/mackerel-plugin-redis
  255. github.com/yucchiy/mackerel-agent-plugins/mackerel-plugin-redis
  256. github.com/yyoshiki41/mackerel-agent-plugins/mackerel-plugin-redis
  257. github.com/zencube/zazen/src

Imported only in test by 3 package(s)

  1. github.com/alphagov/govuk_crawler_worker
  2. github.com/austinov/redsync.go/redsync
  3. github.com/cghsystems/godata/main

Imports 1 package(s)

  1. github.com/fzzy/radix/redis/resp

Test imports 1 package(s)

  1. github.com/stretchr/testify/assert