安装redis,使用一种你熟悉的高级语言(例如ruby,python等)在redis里创建数据并成功访问作为测试
=======================================================================================================
1.安装
[root@ractdg3 download]# ll
-rw-r--r-- 1 root root 1048914 01-15 14:36 redis-2.8.4.tar.gz
[root@ractdg3 download]# tar xzf redis-2.8.4.tar.gz
[root@ractdg3 download]# ll
drwxrwxr-x 6 root root 4096 01-14 00:09 redis-2.8.4
-rw-r--r-- 1 root root 1048914 01-15 14:36 redis-2.8.4.tar.gz
[root@ractdg3 download]# cd redis-2.8.4
[root@ractdg3 redis-2.8.4]# ls
00-RELEASENOTES CONTRIBUTING deps Makefile README runtest src utils
BUGS COPYING INSTALL MANIFESTO redis.conf sentinel.conf tests
[root@ractdg3 redis-2.8.4]# ll
总计 108
-rw-rw-r-- 1 root root 9549 01-14 00:09 00-RELEASENOTES
-rw-rw-r-- 1 root root 52 01-14 00:09 BUGS
-rw-rw-r-- 1 root root 1439 01-14 00:09 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 01-14 00:09 COPYING
drwxrwxr-x 6 root root 4096 01-14 00:09 deps
-rw-rw-r-- 1 root root 11 01-14 00:09 INSTALL
-rw-rw-r-- 1 root root 151 01-14 00:09 Makefile
-rw-rw-r-- 1 root root 4223 01-14 00:09 MANIFESTO
-rw-rw-r-- 1 root root 4401 01-14 00:09 README
-rw-rw-r-- 1 root root 30113 01-14 00:09 redis.conf
-rwxrwxr-x 1 root root 271 01-14 00:09 runtest
-rw-rw-r-- 1 root root 5662 01-14 00:09 sentinel.conf
drwxrwxr-x 2 root root 4096 01-14 00:09 src
drwxrwxr-x 8 root root 4096 01-14 00:09 tests
drwxrwxr-x 2 root root 4096 01-14 00:09 utils
[root@ractdg3 redis-2.8.4]# make
zmalloc.o: In function `zmalloc_used_memory':
/var/lib/tcommsvr/redis-2.8.0-rc4/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
collect2: ld returned 1 exit status
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/var/lib/tcommsvr/redis-2.8.0-rc4/src'
make: *** [all] Error 2
产生原因:
linux为32位版本。
查看方式:getconf LONG_BIT
解决办法:
执行make命令时加参数:make CFLAGS="-march=i686"
make CFLAGS="-march=i686"
2.启动:
[root@ractdg3 src]# ./redis-server --port 9999
[15894] 15 Jan 16:20:23.114 * Max number of open files set to 10032
[15894] 15 Jan 16:20:23.117 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
...
3.测试连接
[root@ractdg3 redis-2.8.4]# telnet localhost 9999
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
get a^H
$-1
set a
-ERR wrong number of arguments for 'set' command
set hpp 4
+OK
set hoge 4
+OK
abcd
-ERR unknown command 'abcd'
set hoge 4
+OK
get hoge
$1
4
setex foo 5 3
+OK
get foo
$-1
get foo
$-1
setex foo 5 10
+OK
4.安装Python
4.1.下载源代码
http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tar.bz2
4.2. 安装 Python
$ tar –jxvf Python-2.7.6.tgz
$ cd Python-2.7.6
./configure
make
make install
4.3 测试打开python
[root@ractdg3 redis-2.7.2]# python
Python 2.7.6 (default, Jan 16 2014, 17:54:06)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> r= redis.StrictRedis(host='localhost',port=6379,db=0)
>>> r.set('foo','bar')
4.4 启动redis
[root@ractdg3 /]# cd /download/redis-2.8.4/
[root@ractdg3 redis-2.8.4]# vi redis.conf
[root@ractdg3 redis-2.8.4]# src/redis-server redis.conf
[28781] 17 Jan 09:50:40.200 * Max number of open files set to 10032
[28781] 17 Jan 09:50:40.203 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.4 (00000000/0) 32 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 28781
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[28781] 17 Jan 09:50:40.205 # Server started, Redis version 2.8.4
[28781] 17 Jan 09:50:40.205 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[28781] 17 Jan 09:50:40.206 * The server is now ready to accept connections on port 6379
4.5 使用python 连接redis
[root@ractdg3 opt]# python
Python 2.7.6 (default, Jan 16 2014, 17:54:06)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> redisClient=redis.StrictRedis(host='127.0.0.1',port=6379,db=0)
>>> redisClient.set('test_redis','Hello Python')
True
>>> value=redisClient.get('test_redis')
>>> print value
Hello Python
>>> redisClient.delete('test_redis')
True
>>> value=redisClient.get('test_redis')
>>> print value
None
>>>
4.6 4.测试实例:
4.6 4.1.把文本数据导入到redis
[root@ractdg3 backup]# cat test_data.txt
wolys # wolysopen111 # wolys@21cn.com
coralshanshan # 601601601 # zss1984@126.com
pengfeihuchao # woaidami # 294522652@qq.com
simulategirl # @#$9608125 # simulateboy@163.com
daisypp # 12345678 # zhoushigang_123@163.com
sirenxing424 # tfiloveyou # sirenxing424@126.com
raininglxy # 1901061139 # lixinyu23@qq.com
leochenlei # leichenlei # chenlei1201@gmail.com
z370433835 # lkp145566 # 370433835@qq.com
4.6 4.2.创建命令脚本
[root@ractdg3 backup]# vi imp_redis.py
[root@ractdg3 backup]# cat imp_redis.py
import redis
import re
pool = redis.ConnectionPool(host='127.0.0.1', port=6379)
r = redis.Redis(connection_pool=pool)
pipe = r.pipeline()
p=re.compile(r'(.*)\s#\s(.*)\s#\s(.*)');
pipe = r.pipeline()
f = open("/opt/backup/test_data.txt")
matchs=p.findall(f.read())
for user in matchs:
key='users_%s' %user[0].strip()
pipe.hset(key,'pwd',user[1].strip()).hset(key,'email',user[2].strip())
pipe.execute()
f.close()
4.6 4.3.执行脚本
[root@ractdg3 backup]# python imp_redis.py
4.6 4.4.查看导入数据
[root@ractdg3 src]# redis-cli
-bash: redis-cli: command not found
[root@ractdg3 src]# ./redis-cli
127.0.0.1:6379> keys *
1) "users_simulategirl"
2) "users_wolys"
3) "users_raininglxy"
4) "users_daisypp"
5) "users_coralshanshan"
6) "users_pengfeihuchao"
7) "users_leochenlei"
8) "hoge"
9) "users_sirenxing424"
10) "users_z370433835"
127.0.0.1:6379>
[root@ractdg3 src]#
=======================================================================================================
1.安装
[root@ractdg3 download]# ll
-rw-r--r-- 1 root root 1048914 01-15 14:36 redis-2.8.4.tar.gz
[root@ractdg3 download]# tar xzf redis-2.8.4.tar.gz
[root@ractdg3 download]# ll
drwxrwxr-x 6 root root 4096 01-14 00:09 redis-2.8.4
-rw-r--r-- 1 root root 1048914 01-15 14:36 redis-2.8.4.tar.gz
[root@ractdg3 download]# cd redis-2.8.4
[root@ractdg3 redis-2.8.4]# ls
00-RELEASENOTES CONTRIBUTING deps Makefile README runtest src utils
BUGS COPYING INSTALL MANIFESTO redis.conf sentinel.conf tests
[root@ractdg3 redis-2.8.4]# ll
总计 108
-rw-rw-r-- 1 root root 9549 01-14 00:09 00-RELEASENOTES
-rw-rw-r-- 1 root root 52 01-14 00:09 BUGS
-rw-rw-r-- 1 root root 1439 01-14 00:09 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 01-14 00:09 COPYING
drwxrwxr-x 6 root root 4096 01-14 00:09 deps
-rw-rw-r-- 1 root root 11 01-14 00:09 INSTALL
-rw-rw-r-- 1 root root 151 01-14 00:09 Makefile
-rw-rw-r-- 1 root root 4223 01-14 00:09 MANIFESTO
-rw-rw-r-- 1 root root 4401 01-14 00:09 README
-rw-rw-r-- 1 root root 30113 01-14 00:09 redis.conf
-rwxrwxr-x 1 root root 271 01-14 00:09 runtest
-rw-rw-r-- 1 root root 5662 01-14 00:09 sentinel.conf
drwxrwxr-x 2 root root 4096 01-14 00:09 src
drwxrwxr-x 8 root root 4096 01-14 00:09 tests
drwxrwxr-x 2 root root 4096 01-14 00:09 utils
[root@ractdg3 redis-2.8.4]# make
zmalloc.o: In function `zmalloc_used_memory':
/var/lib/tcommsvr/redis-2.8.0-rc4/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
collect2: ld returned 1 exit status
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/var/lib/tcommsvr/redis-2.8.0-rc4/src'
make: *** [all] Error 2
产生原因:
linux为32位版本。
查看方式:getconf LONG_BIT
解决办法:
执行make命令时加参数:make CFLAGS="-march=i686"
make CFLAGS="-march=i686"
2.启动:
[root@ractdg3 src]# ./redis-server --port 9999
[15894] 15 Jan 16:20:23.114 * Max number of open files set to 10032
[15894] 15 Jan 16:20:23.117 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
...
3.测试连接
[root@ractdg3 redis-2.8.4]# telnet localhost 9999
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
get a^H
$-1
set a
-ERR wrong number of arguments for 'set' command
set hpp 4
+OK
set hoge 4
+OK
abcd
-ERR unknown command 'abcd'
set hoge 4
+OK
get hoge
$1
4
setex foo 5 3
+OK
get foo
$-1
get foo
$-1
setex foo 5 10
+OK
4.安装Python
4.1.下载源代码
http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tar.bz2
4.2. 安装 Python
$ tar –jxvf Python-2.7.6.tgz
$ cd Python-2.7.6
./configure
make
make install
4.3 测试打开python
[root@ractdg3 redis-2.7.2]# python
Python 2.7.6 (default, Jan 16 2014, 17:54:06)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> r= redis.StrictRedis(host='localhost',port=6379,db=0)
>>> r.set('foo','bar')
4.4 启动redis
[root@ractdg3 /]# cd /download/redis-2.8.4/
[root@ractdg3 redis-2.8.4]# vi redis.conf
[root@ractdg3 redis-2.8.4]# src/redis-server redis.conf
[28781] 17 Jan 09:50:40.200 * Max number of open files set to 10032
[28781] 17 Jan 09:50:40.203 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.4 (00000000/0) 32 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 28781
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[28781] 17 Jan 09:50:40.205 # Server started, Redis version 2.8.4
[28781] 17 Jan 09:50:40.205 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[28781] 17 Jan 09:50:40.206 * The server is now ready to accept connections on port 6379
4.5 使用python 连接redis
[root@ractdg3 opt]# python
Python 2.7.6 (default, Jan 16 2014, 17:54:06)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> redisClient=redis.StrictRedis(host='127.0.0.1',port=6379,db=0)
>>> redisClient.set('test_redis','Hello Python')
True
>>> value=redisClient.get('test_redis')
>>> print value
Hello Python
>>> redisClient.delete('test_redis')
True
>>> value=redisClient.get('test_redis')
>>> print value
None
>>>
4.6 4.测试实例:
4.6 4.1.把文本数据导入到redis
[root@ractdg3 backup]# cat test_data.txt
wolys # wolysopen111 # wolys@21cn.com
coralshanshan # 601601601 # zss1984@126.com
pengfeihuchao # woaidami # 294522652@qq.com
simulategirl # @#$9608125 # simulateboy@163.com
daisypp # 12345678 # zhoushigang_123@163.com
sirenxing424 # tfiloveyou # sirenxing424@126.com
raininglxy # 1901061139 # lixinyu23@qq.com
leochenlei # leichenlei # chenlei1201@gmail.com
z370433835 # lkp145566 # 370433835@qq.com
4.6 4.2.创建命令脚本
[root@ractdg3 backup]# vi imp_redis.py
[root@ractdg3 backup]# cat imp_redis.py
import redis
import re
pool = redis.ConnectionPool(host='127.0.0.1', port=6379)
r = redis.Redis(connection_pool=pool)
pipe = r.pipeline()
p=re.compile(r'(.*)\s#\s(.*)\s#\s(.*)');
pipe = r.pipeline()
f = open("/opt/backup/test_data.txt")
matchs=p.findall(f.read())
for user in matchs:
key='users_%s' %user[0].strip()
pipe.hset(key,'pwd',user[1].strip()).hset(key,'email',user[2].strip())
pipe.execute()
f.close()
4.6 4.3.执行脚本
[root@ractdg3 backup]# python imp_redis.py
4.6 4.4.查看导入数据
[root@ractdg3 src]# redis-cli
-bash: redis-cli: command not found
[root@ractdg3 src]# ./redis-cli
127.0.0.1:6379> keys *
1) "users_simulategirl"
2) "users_wolys"
3) "users_raininglxy"
4) "users_daisypp"
5) "users_coralshanshan"
6) "users_pengfeihuchao"
7) "users_leochenlei"
8) "hoge"
9) "users_sirenxing424"
10) "users_z370433835"
127.0.0.1:6379>
[root@ractdg3 src]#