项目作者: duct-framework

项目描述 :
Integrant methods for connecting to a Redis database via Carmine
高级语言: Clojure
项目地址: git://github.com/duct-framework/database.redis.carmine.git
创建时间: 2017-06-05T14:18:52Z
项目社区:https://github.com/duct-framework/database.redis.carmine

开源协议:

下载


Duct database.redis.carmine

Build Status

Integrant methods for connecting to a Redis database via
Carmine.

Installation

To install, add the following to your project :dependencies:

  1. [duct/database.redis.carmine "0.1.1"]

Usage

This library provides two things: a Boundary record that holds
connection options for Carmine, and a multimethod for
:duct.database.redis/carmine that initiates a those options into the
Boundary.

  1. {:duct.database.redis/carmine {:spec {:host "127.0.0.1", :port 6379}}}

When you write functions against the Redis database, consider using a
protocol and extending the Boundary record. This will allow you to
easily mock or stub out the database using a tool like Shrubbery.

Example

Consider a redis database where users are stored as hashmap with keys
like user:{username}.

The connection spec needed by Carmine can be extracted from this module
Boundary by using the :conn-opts key.

  1. (ns my-project.boundary.user-db
  2. (:require [duct.database.redis.carmine]
  3. [taoensso.carmine :as car :refer (wcar)]))
  4. (defprotocol UserDatabase
  5. (get-user [db username]))
  6. (extend-protocol UserDatabase
  7. duct.database.redis.carmine.Boundary
  8. (get-user [db username]
  9. (car/wcar (:conn-opts db)
  10. (car/hgetall (str "user:" username)))))

License

Copyright © 2018 James Reeves

Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.