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
796d05f8
Commit
796d05f8
authored
Mar 24, 2009
by
antirez
Browse files
Python client library updated, thanks to Ludo!
parent
5a6948fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
client-libraries/python/redis.py
View file @
796d05f8
...
@@ -140,6 +140,19 @@ class Redis(object):
...
@@ -140,6 +140,19 @@ class Redis(object):
self
.
_write
(
'GET %s
\r\n
'
%
name
)
self
.
_write
(
'GET %s
\r\n
'
%
name
)
return
self
.
_get_value
()
return
self
.
_get_value
()
def
mget
(
self
,
*
args
):
"""
>>> r = Redis()
>>> r.set('a', 'pippo'), r.set('b', 15), r.set('c', '
\\
r
\\
naaa
\\
nbbb
\\
r
\\
ncccc
\\
nddd
\\
r
\\
n'), r.set('d', '
\\
r
\\
n')
('OK', 'OK', 'OK', 'OK')
>>> r.mget('a', 'b', 'c', 'd')
['pippo', '15', '
\\
r
\\
naaa
\\
nbbb
\\
r
\\
ncccc
\\
nddd
\\
r
\\
n', '
\\
r
\\
n']
>>>
"""
self
.
connect
()
self
.
_write
(
'MGET %s
\r\n
'
%
' '
.
join
(
args
))
return
self
.
_get_multi_response
()
def
incr
(
self
,
name
,
amount
=
1
):
def
incr
(
self
,
name
,
amount
=
1
):
"""
"""
>>> r = Redis()
>>> r = Redis()
...
@@ -827,6 +840,26 @@ class Redis(object):
...
@@ -827,6 +840,26 @@ class Redis(object):
self
.
_write
(
'%s
\r\n
'
%
(
'FLUSHALL'
if
all_dbs
else
'FLUSHDB'
))
self
.
_write
(
'%s
\r\n
'
%
(
'FLUSHALL'
if
all_dbs
else
'FLUSHDB'
))
return
self
.
_get_simple_response
()
return
self
.
_get_simple_response
()
def
info
(
self
):
"""
>>> r = Redis()
>>> info = r.info()
>>> info and isinstance(info, dict)
True
>>> isinstance(info.get('connected_clients'), int)
True
>>>
"""
self
.
connect
()
self
.
_write
(
'INFO
\r\n
'
)
info
=
dict
()
for
l
in
self
.
_get_value
().
split
(
'
\r\n
'
):
if
not
l
:
continue
k
,
v
=
l
.
split
(
':'
,
1
)
info
[
k
]
=
int
(
v
)
if
v
.
isdigit
()
else
v
return
info
def
_get_value
(
self
,
negative_as_nil
=
False
):
def
_get_value
(
self
,
negative_as_nil
=
False
):
data
=
self
.
_read
().
strip
()
data
=
self
.
_read
().
strip
()
if
data
==
'nil'
or
(
negative_as_nil
and
data
==
'-1'
):
if
data
==
'nil'
or
(
negative_as_nil
and
data
==
'-1'
):
...
...
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