diff options
author | antirez <antirez@gmail.com> | 2009-06-03 16:03:21 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2009-06-03 16:03:21 +0200 |
commit | f7acd60336702b273886ef49650de34b143cbf36 (patch) | |
tree | ca3d4a4f78af560ba953022485fab2af38f6cb26 /client-libraries | |
parent | e52c65b90af21d1eba73ddc0a75eedba69b2f7b8 (diff) | |
download | redis-f7acd60336702b273886ef49650de34b143cbf36.tar.gz |
Python lib updated
Diffstat (limited to 'client-libraries')
-rw-r--r-- | client-libraries/python/redis.py | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/client-libraries/python/redis.py b/client-libraries/python/redis.py index f0e4cd45b..9618901ea 100644 --- a/client-libraries/python/redis.py +++ b/client-libraries/python/redis.py @@ -1,7 +1,12 @@ -#!/usr/bin/python +#!/usr/bin/env python """ redis.py - A client for the Redis daemon. +History: + + - 20090603 fix missing errno import, add sunion and sunionstore commands, + generalize shebang (Jochen Kupperschmidt) + """ __author__ = "Ludovico Magnocavallo <ludo\x40qix\x2eit>" @@ -17,6 +22,7 @@ __date__ = "$LastChangedDate: 2009-03-17 16:15:55 +0100 (Mar, 17 Mar 2009) $"[18 import socket import decimal +import errno BUFSIZE = 4096 @@ -794,6 +800,52 @@ class Redis(object): self._write('SMEMBERS %s\r\n' % name) return set(self.get_response()) + def sunion(self, *args): + """ + >>> r = Redis(db=9) + >>> res = r.delete('s1') + >>> res = r.delete('s2') + >>> res = r.delete('s3') + >>> r.sadd('s1', 'a') + 1 + >>> r.sadd('s2', 'a') + 1 + >>> r.sadd('s3', 'b') + 1 + >>> r.sunion('s1', 's2', 's3') + set([u'a', u'b']) + >>> r.sadd('s2', 'c') + 1 + >>> r.sunion('s1', 's2', 's3') + set([u'a', u'c', u'b']) + >>> + """ + self.connect() + self._write('SUNION %s\r\n' % ' '.join(args)) + return set(self.get_response()) + + def sunionstore(self, dest, *args): + """ + >>> r = Redis(db=9) + >>> res = r.delete('s1') + >>> res = r.delete('s2') + >>> res = r.delete('s3') + >>> r.sadd('s1', 'a') + 1 + >>> r.sadd('s2', 'a') + 1 + >>> r.sadd('s3', 'b') + 1 + >>> r.sunionstore('s4', 's1', 's2', 's3') + 2 + >>> r.smembers('s4') + set([u'a', u'b']) + >>> + """ + self.connect() + self._write('SUNIONSTORE %s %s\r\n' % (dest, ' '.join(args))) + return self.get_response() + def select(self, db): """ >>> r = Redis(db=9) |