溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

suse11安裝測試redis

發(fā)布時間:2020-06-28 10:42:24 來源:網(wǎng)絡(luò) 閱讀:1140 作者:lang71225090 欄目:關(guān)系型數(shù)據(jù)庫

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類型數(shù)據(jù))
SLES11-108:~ # redis-cli  
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> help set   #查看幫助參數(shù),在命令的前面加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
...
后續(xù)省略


redis 127.0.0.1:6379> lpush test a b c #該命令會創(chuàng)建該鍵及與其關(guān)聯(lián)的List,之后在將參數(shù)中的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')  #設(shè)置一個字符串類型的名稱為test的key,內(nèi)容為abc
True
>>> a.get('test')   #顯示該test的內(nèi)容
'abc'
>>> a.dbsize()   #查看庫里有多少數(shù)據(jù)
1L
>>> a.get('test1')   #get 一個庫里沒有的,顯示為空
>>> a.delete('test')  #刪除
True
>>> a.dbsize()   #再查看庫里的數(shù)據(jù),沒有了
0L
>>> a.exists('test')  #判斷 該名稱的的key 是否存在,因為剛刪除,為空
False
>>> a.set('mykey','cde')  #新加一個mykey名稱的key
True
>>> a.exists('mykey')  #判斷為真 ,證明添加上了
True
>>> a.keys()   #查看庫里key的列表
['mykey']
>>> quit() #退出

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI