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 244 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/fancysupport/radix/bench
  78. github.com/fancysupport/radix/examples
  79. github.com/fbq/irc/irclog
  80. github.com/frodebjerke/beeroclock-api/redisclient
  81. github.com/frodetbj/beeroclock-api/redisclient
  82. github.com/fujin/tetragrammaton
  83. github.com/fujiwara/go-redis-setlock
  84. github.com/fzzy/radix/bench
  85. github.com/fzzy/radix/examples
  86. github.com/fzzy/radix/extra/cluster
  87. github.com/fzzy/radix/extra/pool
  88. github.com/fzzy/radix/extra/pubsub
  89. github.com/fzzy/radix/extra/sentinel
  90. github.com/gavincabbage/gbot/core
  91. github.com/gnagel/go-connection_pool/connection_pool/redis_connection_pool
  92. github.com/gnagel/go-redis_pool/redis_pool
  93. github.com/gpjt/stupid-proxy
  94. github.com/guregu/redsync.go/redsync
  95. github.com/hartfordfive/golog
  96. github.com/heydabop/yaircb
  97. github.com/hico-horiuchi/mackerel-agent-plugins/mackerel-plugin-redis
  98. github.com/hiroakis/go-check-plugins/check-redis
  99. github.com/hiroakis/mackerel-agent-plugins/mackerel-plugin-redis
  100. github.com/houst0n/gamekeeper/gamekeeper
  101. github.com/ian-lewis-cs/radix/bench
  102. github.com/ian-lewis-cs/radix/examples
  103. github.com/ivanabc/radix/bench
  104. github.com/ivanabc/radix/examples
  105. github.com/jansichermann/RedisFactory
  106. github.com/jansichermann/apiserver
  107. github.com/jansichermann/radix/bench
  108. github.com/jansichermann/radix/examples
  109. github.com/jansichermann/redisinterface
  110. github.com/jeremy-clerc/rediboard
  111. github.com/jimmysawczuk/norad/src/norad
  112. github.com/jonas747/fortia/rdb
  113. github.com/jonas747/yagpdb/automod
  114. github.com/jonas747/yagpdb/autorole
  115. github.com/jonas747/yagpdb/aylien
  116. github.com/jonas747/yagpdb/bot
  117. github.com/jonas747/yagpdb/commands
  118. github.com/jonas747/yagpdb/common
  119. github.com/jonas747/yagpdb/common/configstore
  120. github.com/jonas747/yagpdb/common/pubsub
  121. github.com/jonas747/yagpdb/customcommands
  122. github.com/jonas747/yagpdb/logs
  123. github.com/jonas747/yagpdb/moderation
  124. github.com/jonas747/yagpdb/notifications
  125. github.com/jonas747/yagpdb/reddit
  126. github.com/jonas747/yagpdb/reminders
  127. github.com/jonas747/yagpdb/reputation
  128. github.com/jonas747/yagpdb/serverstats
  129. github.com/jonas747/yagpdb/streaming
  130. github.com/jonas747/yagpdb/web
  131. github.com/josegonzalez/go-radixurl
  132. github.com/joshgarnett/sysminerd
  133. github.com/joshuarubin/radix/bench
  134. github.com/joshuarubin/radix/examples
  135. github.com/kairichard/zreqlo
  136. github.com/kevinpike/kaon
  137. github.com/kinghrothgar/gobin/storage/redis
  138. github.com/kinghrothgar/goblin/storage/redis
  139. github.com/kinghrothgar/redis/pool
  140. github.com/knq/kv/redisstore
  141. github.com/kuba--/yag/pkg/db
  142. github.com/laohanlinux/radix/bench
  143. github.com/laohanlinux/radix/examples
  144. github.com/laohanlinux/utils/kgredis
  145. github.com/leijou/crstats
  146. github.com/lovek323/btstat
  147. github.com/mackerelio/go-check-plugins/check-redis
  148. github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-redis
  149. github.com/mattkanwisher/microservices-book-code/redis
  150. github.com/mattkrea/go-sessions
  151. github.com/mblair/go-by-example/src
  152. github.com/mchmarny/go-counter
  153. github.com/mediocregopher/hyrax/server/storage/redis
  154. github.com/mediocregopher/swapgur/backend
  155. github.com/mgrigajtis/goqueue
  156. github.com/minotar/imgd
  157. github.com/miqui/dray/job
  158. github.com/msanterre/canoe
  159. github.com/najeira/mackerel-agent-plugins/mackerel-plugin-redis
  160. github.com/naokibtn/mackerel-agent-plugins/mackerel-plugin-redis
  161. github.com/ncodes/redlock-go/redlock
  162. github.com/niaquinto/Niq
  163. github.com/nicholaskh/redsync.go/redsync
  164. github.com/noahgoldman/dotaprofiles
  165. github.com/norisu0313/mackerel-agent-plugins/mackerel-plugin-redis
  166. github.com/nurblieh/restos/lib
  167. github.com/pandax381/mackerel-agent-plugins/mackerel-plugin-redis
  168. github.com/pelmers/autocompeter
  169. github.com/peterbe/autocompeter
  170. github.com/phamhongviet/slack-jobs
  171. github.com/phamhongviet/tadis
  172. github.com/phillihq/racoon/plugins/outputs/redis
  173. github.com/phillipCouto/activebrain
  174. github.com/praekelt/unicore-network/server
  175. github.com/projectarkc/psiphon/go/meek-server
  176. github.com/pyama86/mackerel-agent-plugins/mackerel-plugin-redis
  177. github.com/readmill/radix/bench
  178. github.com/readmill/radix/examples
  179. github.com/repsheet/repsheet
  180. github.com/repsheet/visualizer
  181. github.com/repsheet/warden
  182. github.com/richard-lyman/bob
  183. github.com/richardbowden/autocompeter
  184. github.com/richardhenry/go-pipeline/example
  185. github.com/rif/gocmd
  186. github.com/ritzalam/livemeeting
  187. github.com/rlayte/toystore/store/redis
  188. github.com/roeepolegfiverr/gofiverr/connectors
  189. github.com/saifabid/Redis-Golang-Testing
  190. github.com/saifabid/redisCommandTimer
  191. github.com/samalba/docker-cache
  192. github.com/samalba/hipache-go
  193. github.com/samora/ussd-go/sessionstores
  194. github.com/sanderhahn/kudoding
  195. github.com/saromanov/goredisbench
  196. github.com/saromanov/myexampledb
  197. github.com/shawnfeng/sutil/redispool
  198. github.com/shawnfeng/sutil/redispool/cache
  199. github.com/shokunin/ops_scripts/network
  200. github.com/shopsmart/autocompeter
  201. github.com/simonfuhrer/go-check-plugins/check-redis
  202. github.com/skyjia/radix/bench
  203. github.com/skyjia/radix/examples
  204. github.com/soma5mbaas/schemaworker
  205. github.com/souled3000/base/sentinels
  206. github.com/stanaka/go-check-plugins/check-redis
  207. github.com/stefanwille/redis-client-benchmarks/Go
  208. github.com/steventianhao/sslot/games
  209. github.com/steventianhao/sslot/web
  210. github.com/tclamb/redis/pool
  211. github.com/techslides/canoe
  212. github.com/tfzxyinhao/goStart
  213. github.com/tg/radix/bench
  214. github.com/tg/radix/examples
  215. github.com/theskyinflames/go-misc/com.theskyinflames.go.misc/lib_gc_cache/lib_gc_cache_source
  216. github.com/thomdixon/kaon/src
  217. github.com/tom--bo/mackerel-agent-plugins/mackerel-plugin-redis
  218. github.com/tsaikd/gogstash/output/redis
  219. github.com/tyler-sommer/squircy/squircy
  220. github.com/vashstorm/radix/bench
  221. github.com/vashstorm/radix/examples
  222. github.com/vashstorm/radix/extra/cluster
  223. github.com/vashstorm/radix/extra/pool
  224. github.com/vashstorm/radix/extra/pubsub
  225. github.com/vashstorm/radix/extra/sentinel
  226. github.com/vasilcovsky/microservices-book-code/redis
  227. github.com/vharitonsky/model_matcher
  228. github.com/vharitonsky/model_matcher/model_getter
  229. github.com/vharitonsky/push_server
  230. github.com/vharitonsky/radix/bench
  231. github.com/vharitonsky/radix/examples
  232. github.com/vharitonsky/radix/extra/pool
  233. github.com/vharitonsky/radix/extra/pubsub
  234. github.com/vharitonsky/radix/extra/sentinel
  235. github.com/vharitonsky/swarm
  236. github.com/vifino/carbon/modules/middleware
  237. github.com/waniji/mackerel-agent-plugins/mackerel-plugin-redis
  238. github.com/wolfems/fhback
  239. github.com/wowi42/GoLoadB/libgolb
  240. github.com/ygabo/canoe
  241. github.com/ymichael/sessions
  242. github.com/yoheimuta/go-check-plugins/check-redis
  243. github.com/yucchiy/mackerel-agent-plugins/mackerel-plugin-redis
  244. 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