Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
f7acd603
Commit
f7acd603
authored
Jun 03, 2009
by
antirez
Browse files
Python lib updated
parent
e52c65b9
Changes
1
Show whitespace changes
Inline
Side-by-side
client-libraries/python/redis.py
View file @
f7acd603
#!/usr/bin/python
#!/usr/bin/
env
python
""" redis.py - A client for the Redis daemon.
""" 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
\x40
qix
\x2e
it>"
__author__
=
"Ludovico Magnocavallo <ludo
\x40
qix
\x2e
it>"
...
@@ -17,6 +22,7 @@ __date__ = "$LastChangedDate: 2009-03-17 16:15:55 +0100 (Mar, 17 Mar 2009) $"[18
...
@@ -17,6 +22,7 @@ __date__ = "$LastChangedDate: 2009-03-17 16:15:55 +0100 (Mar, 17 Mar 2009) $"[18
import
socket
import
socket
import
decimal
import
decimal
import
errno
BUFSIZE
=
4096
BUFSIZE
=
4096
...
@@ -794,6 +800,52 @@ class Redis(object):
...
@@ -794,6 +800,52 @@ class Redis(object):
self
.
_write
(
'SMEMBERS %s
\r\n
'
%
name
)
self
.
_write
(
'SMEMBERS %s
\r\n
'
%
name
)
return
set
(
self
.
get_response
())
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
):
def
select
(
self
,
db
):
"""
"""
>>> r = Redis(db=9)
>>> r = Redis(db=9)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment