killme2008 / carmine-sentinel

A Clojure library designed to connect redis by sentinel, make carmine to support sentinel.
Eclipse Public License 1.0
14 stars 4 forks source link

Feature: Permit redirection from slave, or use of a master, as opposed to sentinel only #10

Open charles-dyfis-net opened 7 years ago

charles-dyfis-net commented 7 years ago

Running the role command on establishing a connection will return master, slave or sentinel. Proceeding to current logic in the sentinel case, while redirecting to the master returned in the result of said query in the slave case or using the connection one already has for data/queries in the master case, would serve to generalize this library for use in all single-master redis clusters, including those that don't actually use Sentinel; or those where access to the Sentinel nodes is not permitted from clients.

charles-dyfis-net commented 7 years ago

This ticket is largely filed as a request for comments -- if a patch implementing this functionality were forthcoming (which it may or may not be), would there be upstream interest in merging it?

ylgrgyq commented 5 years ago

If you want to use this library in single-master case without sentinel, you can just leave :master-name and :sentinel-group configs to nil and provide hostname and port for the target redis server in :spec like:

(ns xxx
  (:require [taoensso.carmine :as car]
            [carmine-sentinel.core :as car-sentinel]))

(def server-spec
  {:host       "127.0.0.1"
   :port       6379})

(defmacro wcar* [& body]
  (car-sentinel/wcar {:pool           pool
                      :spec           server-spec}
    ~@body))

(wcar*
  (car/set "x" 1))

So carmine-sentinel will not ask any sentinel for the master redis address and just connect to the single redis on "127.0.0.1:6379".