资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

suse11安装测试redis

suse11 安装测试redis
一,下载安装redis 最新源码包
wget http://redis.googlecode.com/files/redis-2.6.13.tar.gz
--2013-05-12 18:09:57--  http://redis.googlecode.com/files/redis-2.6.13.tar.gz
Resolving redis.googlecode.com... 173.194.72.82, 2404:6800:4008:c00::52
Connecting to redis.googlecode.com|173.194.72.82|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 994331 (971K) [application/x-gzip]
Saving to: `redis-2.6.13.tar.gz'


100%[======================================================================================>] 994,331     3.26M/s   in 0.3s    


2013-05-12 18:09:57 (3.26 MB/s) - `redis-2.6.13.tar.gz' saved [994331/994331]
SLES11-108:~/NOSQL # tar zxvf redis-2.6.13.tar.gz
SLES11-108:~/nosql # cd redis-2.6.13/
make
   CC sentinel.o
   LINK redis-server
   INSTALL redis-sentinel
   CC redis-cli.o
   LINK redis-cli
   CC redis-benchmark.o
   LINK redis-benchmark
   CC redis-check-dump.o
   LINK redis-check-dump
   CC redis-check-aof.o
   LINK redis-check-aof


Hint: To run 'make test' is a good idea ;)
SLES11-108:~/nosql/redis-2.6.13/src # cp redis-server /usr/local/bin/
SLES11-108:~/nosql/redis-2.6.13/src # cp redis-cli /usr/local/bin/
SLES11-108:~/nosql/redis-2.6.13/src # cp ../redis.conf  /etc/


SLES11-108:~/nosql/redis-2.6.13/src #


daemonize yesSLES11-108:/etc # cat /etc/redis.conf  |grep -Ev "^#|^$"
pidfile /var/run/redis.pid
port 6379
timeout 0
tcp-keepalive 0
loglevel notice
logfile stdout
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
二,启动redis
SLES11-108:/etc # ps -ef |grep redis
root     23801     1  0 18:16 ?        00:00:00 redis-server /etc/redis.conf
root     23805 21983  0 18:17 pts/0    00:00:00 grep redis
SLES11-108:/etc # netstat -tplun |grep 6379
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      23801/redis-server  
SLES11-108:/etc #
三,测试redis  (测试list类型数据)
SLES11-108:~ # redis-cli  
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> help set   #查看帮助参数,在命令的前面加help


 SET key value
 summary: Set the string value of a key
 since: 1.0.0
 group: string
 redis 127.0.0.1:6379> help @set  #如果要查看一个类型的全部命令 加@


 SADD key member [member ...]
 summary: Add one or more members to a set
 since: 1.0.0


 SCARD key
 summary: Get the number of members in a set
 since: 1.0.0


 SDIFF key [key ...]
 summary: Subtract multiple sets
 since: 1.0.0
...
后续省略


redis 127.0.0.1:6379> lpush test a b c #该命令会创建该键及与其关联的List,之后在将参数中的values从左到右依次插入。
(integer) 3
redis 127.0.0.1:6379> lrange test 0 -1 #取链表中的全部元素,其中0表示第一个元素,-1表示最后一个元素。
1) "c"
2) "b"
3) "a"
redis 127.0.0.1:6379> lpushx test1 d #库中没有该键值,显示为0
(integer) 0
redis 127.0.0.1:6379> lpushx test d  # 库中有该键值,并且把刚刚加的d 添加进去了
(integer) 4
redis 127.0.0.1:6379> lrange test1
(error) ERR wrong number of arguments for 'lrange' command
redis 127.0.0.1:6379> lrange test1 0 -1
(empty list or set)
redis 127.0.0.1:6379> lrange test 0 -1
1) "d"
2) "c"
3) "b"
4) "a"
redis 127.0.0.1:6379>





四,下载安装python连接redis模块
SLES11-108:~/nosql # wget https://pypi.python.org/packages/source/r/redis/redis-2.7.4.tar.gz
--2013-05-12 18:18:58--  https://pypi.python.org/packages/source/r/redis/redis-2.7.4.tar.gz
Resolving pypi.python.org... 140.211.10.69
Connecting to pypi.python.org|140.211.10.69|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 79715 (78K) [application/octet-stream]
Saving to: `redis-2.7.4.tar.gz'


100%[======================================================================================>] 79,715       183K/s   in 0.4s    


2013-05-12 18:18:59 (183 KB/s) - `redis-2.7.4.tar.gz' saved [79715/79715]
SLES11-108:~/nosql/redis-2.7.4 # python setup.py  install
/usr/lib64/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: 'test_suite'
 warnings.warn(msg)
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/redis
copying redis/exceptions.py -> build/lib/redis
copying redis/_compat.py -> build/lib/redis
copying redis/connection.py -> build/lib/redis
copying redis/client.py -> build/lib/redis
copying redis/__init__.py -> build/lib/redis
copying redis/utils.py -> build/lib/redis
running install_lib
creating /usr/local/lib64/python2.6
creating /usr/local/lib64/python2.6/site-packages
creating /usr/local/lib64/python2.6/site-packages/redis
copying build/lib/redis/exceptions.py -> /usr/local/lib64/python2.6/site-packages/redis
copying build/lib/redis/_compat.py -> /usr/local/lib64/python2.6/site-packages/redis
copying build/lib/redis/connection.py -> /usr/local/lib64/python2.6/site-packages/redis
copying build/lib/redis/client.py -> /usr/local/lib64/python2.6/site-packages/redis
copying build/lib/redis/__init__.py -> /usr/local/lib64/python2.6/site-packages/redis
copying build/lib/redis/utils.py -> /usr/local/lib64/python2.6/site-packages/redis
byte-compiling /usr/local/lib64/python2.6/site-packages/redis/exceptions.py to exceptions.pyc
byte-compiling /usr/local/lib64/python2.6/site-packages/redis/_compat.py to _compat.pyc
byte-compiling /usr/local/lib64/python2.6/site-packages/redis/connection.py to connection.pyc
byte-compiling /usr/local/lib64/python2.6/site-packages/redis/client.py to client.pyc
byte-compiling /usr/local/lib64/python2.6/site-packages/redis/__init__.py to __init__.pyc
byte-compiling /usr/local/lib64/python2.6/site-packages/redis/utils.py to utils.pyc
running install_egg_info
Writing /usr/local/lib64/python2.6/site-packages/redis-2.7.4-py2.6.egg-info
五,简单测试python连接redis
SLES11-108:~/nosql/redis-2.7.4 # python
Python 2.6 (r26:66714, Feb  2 2012, 16:59:44)
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import redis
>>> a = redis.testredis(host='localhost',port=6379,db=0)
Traceback (most recent call last):
 File "", line 1, in
AttributeError: 'module' object has no attribute 'testredis'  
>>> a = redis.Redis(host='localhost',port=6379,db=0)    
>>> a.set('test','abc')  #设置一个字符串类型的名称为test的key,内容为abc
True
>>> a.get('test')   #显示该test的内容
'abc'
>>> a.dbsize()   #查看库里有多少数据
1L
>>> a.get('test1')   #get 一个库里没有的,显示为空
>>> a.delete('test')  #删除
True
>>> a.dbsize()   #再查看库里的数据,没有了
0L
>>> a.exists('test')  #判断 该名称的的key 是否存在,因为刚删除,为空
False
>>> a.set('mykey','cde')  #新加一个mykey名称的key
True
>>> a.exists('mykey')  #判断为真 ,证明添加上了
True
>>> a.keys()   #查看库里key的列表
['mykey']
>>> quit() #退出

创新互联成立与2013年,是专业互联网技术服务公司,拥有项目成都网站制作、做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元耿马做网站,已为上家服务,为耿马各地企业和个人服务,联系电话:028-86922220


当前文章:suse11安装测试redis
文章路径:http://www.cdkjz.cn/article/jicghp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220