Skip to content

Instantly share code, notes, and snippets.

@azat
Created June 8, 2014 13:30
Show Gist options
  • Save azat/b67474c882a6d7d519bc to your computer and use it in GitHub Desktop.
Save azat/b67474c882a6d7d519bc to your computer and use it in GitHub Desktop.
From 0eaed7aadfc62b55aee51a740050a45aab5b302d Mon Sep 17 00:00:00 2001
From: Qolt <ysemenov.mail@gmail.com>
Date: Sun, 23 Jun 2013 20:16:30 +0400
Subject: [PATCH] Added Boostcache class, to iprovide a Python interface for
boostcache (https://github.com/azat/boostcache)
---
redis/__init__.py | 4 ++--
redis/client.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/redis/__init__.py b/redis/__init__.py
index 9549ec7..92b68c4 100644
--- a/redis/__init__.py
+++ b/redis/__init__.py
@@ -1,4 +1,4 @@
-from redis.client import Redis, StrictRedis
+from redis.client import Redis, StrictRedis, Boostcache
from redis.connection import (
BlockingConnectionPool,
ConnectionPool,
@@ -23,7 +23,7 @@
VERSION = tuple(map(int, __version__.split('.')))
__all__ = [
- 'Redis', 'StrictRedis', 'ConnectionPool', 'BlockingConnectionPool',
+ 'Boostcache', 'Redis', 'StrictRedis', 'ConnectionPool', 'BlockingConnectionPool',
'Connection', 'UnixDomainSocketConnection',
'RedisError', 'ConnectionError', 'ResponseError', 'AuthenticationError',
'InvalidResponse', 'DataError', 'PubSubError', 'WatchError', 'from_url',
diff --git a/redis/client.py b/redis/client.py
index 963d936..4445206 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -2091,3 +2091,47 @@ def release(self):
if existing >= self.acquired_until:
self.redis.delete(self.name)
self.acquired_until = None
+
+class Boostcache(StrictRedis):
+ RESPONSE_CALLBACKS = dict_merge(
+ StrictRedis.RESPONSE_CALLBACKS,
+ {
+ 'HSET': lambda r: nativestr(r) == 'OK',
+ 'ATSET': lambda r: nativestr(r) == 'OK',
+ }
+ )
+
+ def __init__(self, **kwargs):
+ super(Boostcache, self).__init__(**kwargs)
+
+ def hget(self, key):
+ "Return the value of ``key`` "
+ return self.execute_command('HGET', key)
+
+ def hset(self, key, value):
+ "Set the ``value`` of ``key`` "
+ return self.execute_command('HSET', key, value)
+
+ def hdel(self, key):
+ "Delete ``key``"
+ return self.execute_command('HDEL', key)
+
+ def atget(self, key):
+ "Return the value of ``key`` "
+ return self.execute_command('ATGET', key)
+
+ def atset(self, key, value):
+ "Set the ``value`` of ``key`` "
+ return self.execute_command('ATSET', key, value)
+
+ def atdel(self, key):
+ "Delete ``key``"
+ return self.execute_command('ATDEL', key)
+
+ def commands(self):
+ "Return list of commands"
+ return self.execute_command('COMMANDS')
+
+ def version(self):
+ "Return version number"
+ return self.execute_command('VERSION')
--
1.9.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment