蓝晶灵 发表于 2018-11-7 08:15:08

suse11安装测试redis-cm

  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)
  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
  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>  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   10 18:16 ?      00:00:00 redis-server /etc/redis.conf
  root   23805 219830 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
  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
  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)
  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
  SLES11-108:~/nosql/redis-2.7.4 # python setup.pyinstall
  /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, Feb2 2012, 16:59:44)
  ] 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() #退出

页: [1]
查看完整版本: suse11安装测试redis-cm