本文系统centos6.0
Redis服务端:192.168.100.132;port=6379
Redis客户端:192.168.100.132
客户端操作:
安装python支持redis;
1
2
3
4
|
wget https:
//pypi.python.org/packages/source/r/redis/redis-2.9.1.tar.gz
tar zxvf redis-
2.9
.
1
.tar.gz
cd redis-
2.9
.
1
python setup.py install
|
服务端启动redis
1
|
/root/redis-
2.2
.
12
/src/redis-server
|
客户端测试:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
[root@master ~]# python
>>>
import
redis
>>> r = redis.Redis(host=
'192.168.100.132'
,port=
6379
,db=
0
)
//#如果设置了密码,就加上password=密码
>>> r.
set
(
'name'
,
'lansgg'
)
True
>>> r.
get
(
'name'
)
'lansgg'
>>> r.exists(
'name'
)
//#看是否存在这个键值
True
>>> r.
delete
(
'name'
)
1
>>> r.dbsize()
//#库里有多少key,多少条数据
0L
>>> r.
set
(
'name'
,
'lansgg'
)
True
>>> r.flushdb()
// #删除当前数据库的所有数据
True
>>> r.
get
(
'name'
)
>>> r.
set
(
'name'
,
'lansgg'
)
True
>>> r.
set
(
'wm'
,
'leo'
)
True
>>> r.
set
(
'tt'
,
'coffee'
)
True
>>> r.keys()
// # 列出所有键值。
[
'tt'
,
'wm'
,
'name'
]
>>> r.save()
// #强行把数据库保存到硬盘。保存时阻塞
True
>>> r.dbsize()
3L
>>> dir(r)
[
'RESPONSE_CALLBACKS'
,
'__class__'
,
'__contains__'
,
'__delattr__'
,
'__delitem__'
,
'__dict__'
,
'__doc__'
,
'__format__'
,
'__getattribute__'
,
'__getitem__'
,
'__hash__'
,
'__init__'
,
'__module__'
,
'__new__'
,
'__reduce__'
,
'__reduce_ex__'
,
'__repr__'
,
'__setattr__'
,
'__setitem__'
,
'__sizeof__'
,
'__str__'
,
'__subclasshook__'
,
'__weakref__'
,
'_zaggregate'
,
'append'
,
'bgrewriteaof'
,
'bgsave'
,
'bitcount'
,
'bitop'
,
'blpop'
,
'brpop'
,
'brpoplpush'
,
'client_getname'
,
'client_kill'
,
'client_list'
,
'client_setname'
,
'config_get'
,
'config_resetstat'
,
'config_set'
,
'connection_pool'
,
'dbsize'
,
'debug_object'
,
'decr'
,
'delete'
,
'dump'
,
'echo'
,
'eval'
,
'evalsha'
,
'execute_command'
,
'exists'
,
'expire'
,
'expireat'
,
'flushall'
,
'flushdb'
,
'from_url'
,
'get'
,
'getbit'
,
'getrange'
,
'getset'
,
'hdel'
,
'hexists'
,
'hget'
,
'hgetall'
,
'hincrby'
,
'hincrbyfloat'
,
'hkeys'
,
'hlen'
,
'hmget'
,
'hmset'
,
'hscan'
,
'hset'
,
'hsetnx'
,
'hvals'
,
'incr'
,
'incrby'
,
'incrbyfloat'
,
'info'
,
'keys'
,
'lastsave'
,
'lindex'
,
'linsert'
,
'llen'
,
'lock'
,
'lpop'
,
'lpush'
,
'lpushx'
,
'lrange'
,
'lrem'
,
'lset'
,
'ltrim'
,
'mget'
,
'move'
,
'mset'
,
'msetnx'
,
'object'
,
'parse_response'
,
'persist'
,
'pexpire'
,
'pexpireat'
,
'ping'
,
'pipeline'
,
'psetex'
,
'pttl'
,
'publish'
,
'pubsub'
,
'randomkey'
,
'register_script'
,
'rename'
,
'renamenx'
,
'response_callbacks'
,
'restore'
,
'rpop'
,
'rpoplpush'
,
'rpush'
,
'rpushx'
,
'sadd'
,
'save'
,
'scan'
,
'scard'
,
'script_exists'
,
'script_flush'
,
'script_kill'
,
'script_load'
,
'sdiff'
,
'sdiffstore'
,
'sentinel'
,
'sentinel_get_master_addr_by_name'
,
'sentinel_masters'
,
'sentinel_sentinels'
,
'sentinel_slaves'
,
'set'
,
'set_response_callback'
,
'setbit'
,
'setex'
,
'setnx'
,
'setrange'
,
'shutdown'
,
'sinter'
,
'sinterstore'
,
'sismember'
,
'slaveof'
,
'smembers'
,
'smove'
,
'sort'
,
'spop'
,
'srandmember'
,
'srem'
,
'sscan'
,
'strlen'
,
'substr'
,
'sunion'
,
'sunionstore'
,
'time'
,
'transaction'
,
'ttl'
,
'type'
,
'unwatch'
,
'watch'
,
'zadd'
,
'zcard'
,
'zcount'
,
'zincrby'
,
'zinterstore'
,
'zrange'
,
'zrangebyscore'
,
'zrank'
,
'zrem'
,
'zremrangebyrank'
,
'zremrangebyscore'
,
'zrevrange'
,
'zrevrangebyscore'
,
'zrevrank'
,
'zscan'
,
'zscore'
,
'zunionstore'
]
|
这只是一个简单的测试,为了测试redis是否正常工作,我们安装是否正确;
本文转自 西索oO 51CTO博客,原文链接:http://blog.51cto.com/lansgg/1384196