Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: redis-rs/redis-rs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.5.4
Choose a base ref
...
head repository: redis-rs/redis-rs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.6.0
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Jun 25, 2016

  1. Verified

    This commit was signed with the committer’s verified signature.
    jvnipers Juniper
    Copy the full SHA
    a0777b0 View commit details

Commits on Jul 13, 2016

  1. Bump sha1

    mitsuhiko committed Jul 13, 2016
    Copy the full SHA
    aa5fb91 View commit details
  2. Fixed new sha1 api

    mitsuhiko committed Jul 13, 2016
    Copy the full SHA
    15daddc View commit details
Showing with 52 additions and 32 deletions.
  1. +8 −4 Cargo.toml
  2. +8 −2 Makefile
  3. +13 −13 src/connection.rs
  4. +10 −5 src/lib.rs
  5. +1 −1 src/script.rs
  6. +6 −1 src/types.rs
  7. +6 −6 tests/test_basic.rs
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "redis"
version = "0.5.4"
version = "0.6.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
keywords = ["redis", "database"]
description = "Redis driver for Rust."
@@ -15,8 +15,12 @@ readme = "README.md"
#[dependencies.url]
#git = "https://github.com/servo/rust-url"

[features]
with-rustc-json = ["rustc-serialize"]
with-unix-sockets = ["unix_socket"]

[dependencies]
sha1 = "0.1.1"
sha1 = "0.2.0"
url = "1.1"
rustc-serialize = "0.3.16"
unix_socket = { version ="0.5.0", optional = true }
rustc-serialize = { version = "0.3.16", optional = true }
unix_socket = { version = "0.5.0", optional = true }
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -2,10 +2,16 @@ build:
@cargo build

test:
@echo "======================================================================"
@echo "Testing without unix_socket"
@RUST_TEST_THREADS=1 cargo test
@echo "======================================================================"
@echo
@RUST_TEST_THREADS=1 cargo test --features="with-rustc-json"
@echo "======================================================================"
@echo "Testing with unix_socket"
@RUST_TEST_THREADS=1 cargo test --features=unix_socket
@echo "======================================================================"
@echo
@RUST_TEST_THREADS=1 cargo test --features="with-rustc-json with-unix-sockets"

bench:
@RUST_TEST_THREADS=1 cargo bench
26 changes: 13 additions & 13 deletions src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
use std::path::PathBuf;
use std::io::{Read, BufReader, Write};
use std::net::{self, TcpStream};
@@ -14,7 +14,7 @@ use types::{RedisResult, Value, ToRedisArgs, FromRedisValue, from_redis_value,
ErrorKind};
use parser::Parser;

#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
use unix_socket::UnixStream;


@@ -39,14 +39,14 @@ pub fn parse_redis_url(input: &str) -> Result<url::Url, ()> {
/// Defines the connection address.
///
/// The fields available on this struct depend on if the crate has been
/// compiled with the `unix_socket` feature or not. The `Tcp` field
/// compiled with the `with-unix-sockets` feature or not. The `Tcp` field
/// is always available, but the `Unix` one is not.
#[derive(Clone, Debug)]
pub enum ConnectionAddr {
/// Format for this is `(host, port)`.
Tcp(String, u16),
/// Format for this is the path to the unix socket.
#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
Unix(PathBuf),
}

@@ -102,7 +102,7 @@ fn url_to_tcp_connection_info(url: url::Url) -> RedisResult<ConnectionInfo> {
})
}

#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
fn url_to_unix_connection_info(url: url::Url) -> RedisResult<ConnectionInfo> {
Ok(ConnectionInfo {
addr: Box::new(ConnectionAddr::Unix(
@@ -118,7 +118,7 @@ fn url_to_unix_connection_info(url: url::Url) -> RedisResult<ConnectionInfo> {
})
}

#[cfg(not(feature="unix_socket"))]
#[cfg(not(feature="with-unix-sockets"))]
fn url_to_unix_connection_info(_: url::Url) -> RedisResult<ConnectionInfo> {
fail!((ErrorKind::InvalidClientConfig,
"This version of redis-rs is not compiled with Unix socket support."));
@@ -139,7 +139,7 @@ impl IntoConnectionInfo for url::Url {

enum ActualConnection {
Tcp(BufReader<TcpStream>),
#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
Unix(UnixStream),
}

@@ -173,7 +173,7 @@ impl ActualConnection {
let buffered = BufReader::new(tcp);
ActualConnection::Tcp(buffered)
}
#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
ConnectionAddr::Unix(ref path) => {
ActualConnection::Unix(try!(UnixStream::connect(path)))
}
@@ -185,7 +185,7 @@ impl ActualConnection {
ActualConnection::Tcp(ref mut reader) => {
reader.get_mut() as &mut Write
}
#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
ActualConnection::Unix(ref mut sock) => {
&mut *sock as &mut Write
}
@@ -199,7 +199,7 @@ impl ActualConnection {
ActualConnection::Tcp(ref mut reader) => {
reader as &mut Read
}
#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
ActualConnection::Unix(ref mut sock) => {
&mut *sock as &mut Read
}
@@ -211,7 +211,7 @@ impl ActualConnection {
ActualConnection::Tcp(ref mut reader) => {
let _ = reader.get_mut().shutdown(net::Shutdown::Both);
}
#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
ActualConnection::Unix(ref mut sock) => {
let _ = sock.shutdown(net::Shutdown::Both);
}
@@ -227,7 +227,7 @@ impl ActualConnection {
ActualConnection::Tcp(ref reader) => {
try!(reader.get_ref().set_write_timeout(dur));
}
#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
ActualConnection::Unix(ref sock) => {
try!(sock.set_write_timeout(dur));
}
@@ -240,7 +240,7 @@ impl ActualConnection {
ActualConnection::Tcp(ref reader) => {
try!(reader.get_ref().set_read_timeout(dur));
}
#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
ActualConnection::Unix(ref sock) => {
try!(sock.set_read_timeout(dur));
}
15 changes: 10 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -52,13 +52,13 @@
//!
//! By default this library does not support unix sockets but starting with
//! redis-rs 0.5.0 you can optionally compile it with unix sockets enabled.
//! For this you just need to enable the `unix_sockets` flag and some of the
//! For this you just need to enable the `with-unix-sockets` flag and some of the
//! otherwise unavailable APIs become available:
//!
//! ```ini
//! [dependencies.redis]
//! version = "*"
//! features = ["unix_socket"]
//! features = ["with-unix-sockets"]
//! ```
//!
//! ## Connection Parameters
@@ -73,7 +73,7 @@
//!
//! The URL format is `redis://[:<passwd>@]<hostname>[:port][/<db>]`
//!
//! In case you have compiled the crate with the `unix_sockets` feature
//! In case you have compiled the crate with the `with-unix-sockets` feature
//! then you can also use a unix URL in this format:
//!
//! `unix:///[:<passwd>@]<path>[?db=<db>]`
@@ -305,12 +305,17 @@
#![deny(non_camel_case_types)]

extern crate url;
extern crate rustc_serialize as serialize;
extern crate sha1;

#[cfg(feature="unix_socket")]
#[cfg(feature="with-rustc-json")]
pub extern crate rustc_serialize as serialize;
#[cfg(feature="with-unix-sockets")]
extern crate unix_socket;

#[doc(hidden)]
#[cfg(feature="with-rustc-json")]
pub use serialize::json::Json;

/* public api */
pub use parser::{parse_redis_value, Parser};
pub use client::Client;
2 changes: 1 addition & 1 deletion src/script.rs
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ impl Script {
hash.update(code.as_bytes());
Script {
code: code.to_string(),
hash: hash.hexdigest(),
hash: hash.digest().to_string(),
}
}

7 changes: 6 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ use std::hash::Hash;
use std::str::{from_utf8, Utf8Error};
use std::collections::{HashMap, HashSet};
use std::convert::From;

#[cfg(feature="with-rustc-json")]
use serialize::json;


@@ -290,7 +292,7 @@ impl RedisError {
// if we connect to a unix socket and the file does not
// exist yet, then we want to treat this as if it was a
// connection refusal.
io::ErrorKind::NotFound => cfg!(feature="unix_socket"),
io::ErrorKind::NotFound => cfg!(feature="with-unix-sockets"),
_ => false,
}
}
@@ -558,6 +560,7 @@ impl<T: ToRedisArgs> ToRedisArgs for Option<T> {
}
}

#[cfg(feature="with-rustc-json")]
impl ToRedisArgs for json::Json {
fn to_redis_args(&self) -> Vec<Vec<u8>> {
// XXX: the encode result needs to be handled properly
@@ -894,6 +897,7 @@ impl FromRedisValue for InfoDict {
}
}

#[cfg(feature="with-rustc-json")]
impl FromRedisValue for json::Json {
fn from_redis_value(v: &Value) -> RedisResult<json::Json> {
let rv = match *v {
@@ -908,6 +912,7 @@ impl FromRedisValue for json::Json {
}
}


impl<T: FromRedisValue> FromRedisValue for Option<T> {
fn from_redis_value(v: &Value) -> RedisResult<Option<T>> {
match *v {
12 changes: 6 additions & 6 deletions tests/test_basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate redis;
extern crate rustc_serialize as serialize;

use redis::{Commands, PipelineCommands};

@@ -8,7 +7,7 @@ use std::thread::{spawn, sleep};
use std::time::Duration;
use std::collections::{HashMap, HashSet};

#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
use std::path::PathBuf;

pub static SERVER_PORT: u16 = 38991;
@@ -28,7 +27,7 @@ impl RedisServer {
.arg("--port").arg(SERVER_PORT.to_string())
.arg("--bind").arg("127.0.0.1");

if cfg!(feature="unix_socket") {
if cfg!(feature="with-unix-sockets") {
cmd.arg("--unixsocket").arg(SERVER_UNIX_PATH);
}

@@ -43,12 +42,12 @@ impl RedisServer {
pub fn foo(&mut self) {
}

#[cfg(not(feature="unix_socket"))]
#[cfg(not(feature="with-unix-sockets"))]
pub fn get_client_addr(&self) -> redis::ConnectionAddr {
redis::ConnectionAddr::Tcp("127.0.0.1".to_string(), SERVER_PORT)
}

#[cfg(feature="unix_socket")]
#[cfg(feature="with-unix-sockets")]
pub fn get_client_addr(&self) -> redis::ConnectionAddr {
redis::ConnectionAddr::Unix(PathBuf::from(SERVER_UNIX_PATH))
}
@@ -240,9 +239,10 @@ fn test_optionals() {
assert_eq!(a, 0i32);
}

#[cfg(feature="with-rustc-json")]
#[test]
fn test_json() {
use serialize::json::Json;
use redis::Json;

let ctx = TestContext::new();
let con = ctx.connection();