Skip to content

Commit

Permalink
Merge branch 'release-0.1.0'
Browse files Browse the repository at this point in the history
albrow committed Aug 17, 2013

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents de5dd79 + ec4bf78 commit 532b83a
Showing 3 changed files with 43 additions and 30 deletions.
56 changes: 34 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Zoom
====

Version: 0.0.1
Version: 0.1.0

A blazing-fast, lightweight ORM-ish library for go and redis.

@@ -27,10 +27,7 @@ Installation
------------

First, you must install redis on your system. [See installation instructions](http://redis.io/download).

By default, Zoom uses a unix socket connection to connect to redis. To do this, you need to enable
socket connections in your redis config file. If you prefer to use tcp/http instead, see the Setup
instructions below.
By default, Zoom will use a tcp/http connection on localhost:6379 (same as the redis default).

To install Zoom itself:

@@ -71,21 +68,29 @@ defaults:

``` go
type Configuration struct {
Address string // Address to connect to. Default: "/tmp/redis.sock"
Network string // Network to use. Default: "unix"
Database int // Database id to use. Default: 0
Address string // Address to connect to. Default: "localhost:6379"
Network string // Network to use. Default: "tcp"
Database int // Database id to use (using SELECT). Default: 0
}
```

So, if you wanted to connect with tcp/http on the default port (6380), you would do this:
If possible, it is ***strongly recommended*** that you use a unix socket connection instead of tcp.
Redis is roughly [50% faster](http://redis.io/topics/benchmarks) this way. To connect with a unix
socket, you must first configure redis to accept socket connections on /tmp/redis.sock (or somewhere else).
If you are unsure how to do this, refer to the [official redis docs](http://redis.io/topics/config) for help.
You might also find the [redis quickstart guide](http://redis.io/topics/quickstart) helpful, especially the bottom
sections.

Then, when you call Zoom.Init(), simply pass in "unix" as the Network and "/tmp/unix.sock" as the Address:


``` go
config := &zoom.Configuration {
Address: "localhost:6380",
Network: "tcp",
Address: "/tmp/redis.sock",
Network: "unix",
}
if err := zoom.Init(config); err != nil {
// handle err
// handle err
}
```

@@ -456,17 +461,12 @@ for _, friend := range fred.Friends {
Testing & Benchmarking
----------------------

**Important:** Before running any tests or benchmarks, make sure that you have redis running and accepting
connections on a unix socket at /tmp/unix.sock. To test if your redis server is properly set up, you can run:

redis-cli -s /tmp/redis.sock -c ping

If you receive PONG in response, then you are good to go. If anything else happens, redis is not setup
properly. Check out the [official redis docs](http://redis.io/topics/config) for help. You might also find
the [redis quickstart guide](http://redis.io/topics/quickstart) helpful, especially the bottom sections.
**IMPORTANT**: Before running any tests or benchmarks, make sure you have a redis-server instance running.
Tests will use a tcp connection on localhost:6379. Benchmarks will use a unix socket connection on /tmp/unix.sock.

All the tests and benchmarks will use database #9. If database #9 is non-empty, they will will throw and
error and not run. (so as to not corrupt your data). Database #9 is flushed at the end of every test/benchmark.
All the tests and benchmarks will use database #9. If database #9 is non-empty, they will
will throw and error and not run. (so as to not corrupt your data). Database #9 is flushed at the end of
every test/benchmark.

### Running the Tests:

@@ -487,6 +487,18 @@ describe what happened.

### Running the Benchmarks:

**Important:** Before running the benchmarks, make sure that you have redis running and accepting
connections on a unix socket at /tmp/unix.sock. The benchmarks use a unix socket connection to ensure
that the times shown reflect the maximum potential speed.

To test if your redis server is properly set up, you can run:

redis-cli -s /tmp/redis.sock -c ping

If you receive PONG in response, then you are good to go. If anything else happens, redis is not setup
properly. Check out the [official redis docs](http://redis.io/topics/config) for help. You might also find
the [redis quickstart guide](http://redis.io/topics/quickstart) helpful, especially the bottom sections.

To run the benchmarks, again make sure you're in the project root directory and run:

go test ./... --bench="."
2 changes: 1 addition & 1 deletion benchmark/benchmark_support.go
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ func NewInvoice(created, updated int64, memo string, personId int64, isPaid bool
// Database helper functions
// setUp() and tearDown()
func setUp() error {
zoom.Init(&zoom.Configuration{Database: 9})
zoom.Init(&zoom.Configuration{Address: "/tmp/redis.sock", Network: "unix", Database: 9})

conn := zoom.GetConn()
defer conn.Close()
15 changes: 8 additions & 7 deletions database.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package zoom

// File contains code strictly related to the database, including
// establishing a connection, instantiating a package-wide db var
// and closing the connection. There are also convenience functions
// for (e.g.) checking if a key exists in redis.
// setting up the database with given config, generating unique,
// random ids, and creating and managing a connection pool. There
// are also convenience functions for (e.g.) checking if a key exists
// in redis.

import (
"github.com/dchest/uniuri"
@@ -13,16 +14,16 @@ import (
)

type Configuration struct {
Address string // Address to connect to. Default: "/tmp/redis.sock"
Network string // Network to use. Default: "unix"
Address string // Address to connect to. Default: "localhost:6379"
Network string // Network to use. Default: "tcp"
Database int // Database id to use (using SELECT). Default: 0
}

var pool *redis.Pool

var defaultConfiguration = Configuration{
Address: "/tmp/redis.sock",
Network: "unix",
Address: "localhost:6379",
Network: "tcp",
Database: 0,
}

0 comments on commit 532b83a

Please sign in to comment.