import collections

import redis

BENCHMARK_FIELDS = [
    'author', 'author_url', 'date_submitted', 'date_updated',
    'name', 'summary', 'tags', 'title', 'url'
]

Benchmark = collections.namedtuple('Benchmark', ' '.join(BENCHMARK_FIELDS))


class McBenchClient(object):
    def __init__(self, redis):
        self.redis = redis

    def get_benchmark_by_id(self, benchmark_id):
        return Benchmark(**self.redis.hgetall('benchmark:%s' % benchmark_id))

    def get_benchmark_by_name(self, name):
        benchmark_id = self.redis.get('benchmark:%s:id', name)
        return self.get_benchmark_by_id(benchmark_id)

    def insert_benchmark(self, benchmark):
        benchmark_id = self.redis.incr('global:next_benchmark_id')
        self.redis.set('benchmark:%s:id' % benchmark.name, benchmark_id)
        self.redis.hmset('benchmark:%s' % benchmark_id, benchmark._asdict())


def from_redis_url(redis_url):
    return McBenchClient(redis.from_url(redis_url))

@@ -4,71 +4,72 @@
 ort 
-collections%0A%0Aimport redis%0A%0ABENCHMARK_FIELDS = %5B%0A    '
+redis%0A%0A%0Aclass Benchmark(object):%0A    def __init__(self, 
 author
-'
 , 
-'
 auth
@@ -74,20 +74,18 @@
 thor_url
-'
 , 
-'
 date_sub
@@ -90,20 +90,18 @@
 ubmitted
-'
 , 
-'
 date_upd
@@ -108,135 +108,516 @@
 ated
-'
 ,%0A    
-'
+             
 name
-'
 , 
-'
 summary
-'
 , 
-'
 tags
-'
 , 
-'
 title
-'
 , 
-'
 url
-'%0A%5D%0A%0ABenchmark = collections.namedtuple('Benchmark', ' '.join(BENCHMARK_FIELDS))
+):%0A        self.author = author%0A        self.author_url = author_url%0A        self.date_submitted = date_submitted%0A        self.date_updated = date_updated%0A        self.name = name%0A        self.summary = summary%0A        self.tags = tags%0A        self.title = title%0A        self.url = url%0A%0A    def __repr__(self):%0A        return '%3CBenchmark: %25s%3E' %25 self.name%0A%0A%0Aclass BenchmarkDoesNotExist(Exception):%0A    pass%0A%0A%0Aclass BenchmarkAlreadyExists(Exception):%0A    pass
 %0A%0A%0Ac
@@ -764,27 +764,15 @@
     
-return Benchmark(**
+data = 
 self
@@ -820,132 +820,384 @@
 _id)
-)%0A%0A    def get_benchmark_by_name(self, name):%0A        benchmark_id = self.redis.get('benchmark:%25s:id', name
+%0A        if not data:%0A            raise BenchmarkDoesNotExist%0A        return Benchmark(**data)%0A%0A    def get_benchmark_by_name(self, name):%0A        benchmark_id = self.redis.get('name:%25s:id' %25 name)%0A        if benchmark_id is None:%0A            raise BenchmarkDoesNotExist%0A        return self.get_benchmark_by_id(benchmark_id
 )%0A
+%0A
  
+   def get_all_benchmarks(self):%0A
        
+ 
 return 
+%5B
 self
@@ -1221,65 +1221,282 @@
 _id(
-benchmark_id)%0A%0A    def insert_benchmark(self, benchmark):
+key%5Blen('benchmark:'):%5D)%0A                for key in self.redis.keys('benchmark:*')%5D%0A%0A    def insert_benchmark(self, benchmark):%0A        benchmark_id = self.redis.get('name:%25s:id' %25 benchmark.name)%0A        if benchmark_id is not None:%0A            raise BenchmarkAlreadyExists
 %0A   
@@ -1583,25 +1583,20 @@
 is.set('
-benchmark
+name
 :%25s:id' 
@@ -1683,16 +1683,21 @@
 ark_id, 
+vars(
 benchmar
@@ -1701,17 +1701,8 @@
 mark
-._asdict(
 ))%0A%0A

Make Benchmark a class, not a namedtuple.