perl 操作redis

来源:互联网 发布:opentsdb java开发 编辑:程序博客网 时间:2024/05/31 19:52
<pre name="code" class="sql"><pre name="code" class="sql">1.查看安装的redis版本jrhrpt01:/root# redis-server --versionRedis server v=2.8.19 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=1138bcb7ae3eee58源码包为redis-2.8.19.tar.gz2.yum -y install  gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses* libmcrypt* libtool-ltdl-devel* make cmake 3.开始编译test-redis:/root/redis-2.8.19# make installHint: It's a good idea to run 'make test' ;)    INSTALL install    INSTALL install    INSTALL install    INSTALL install    INSTALL installmake[1]: Leaving directory `/root/redis-2.8.19/src'4.安装成功之后会在src文件夹内有redis-server和redis-cli两个命令建议将其放到bin下cp redis-server /usr/local/bin/cp redis-cli /usr/local/bin/test-redis:/root/redis-2.8.19# cp redis.conf /etc/5.启动redisredis-server /etc/redis.confredis 设置:1.设置密码# Warning: since Redis is pretty fast an outside user can try up to# 150k passwords per second against a good box. This means that you should# use a very strong password otherwise it will be very easy to break.#requirepass r,uLgt.313 2.# The Append Only File will also be created inside this directory.## Note that you must specify a directory here, not a file name.dir /data01/redis/perl 访问redis:介绍下怎么安装:脚本用到了perl的Redis库,需要先安装这个:test-redis:/root# tar -zxvf Redis-1.955.tar.gz   cd Redis-1.955   ls  perl Makefile.PL   make  make installtest-redis:/root# perldoc   Redistest-redis:/root# perl a1.pl Can't locate Try/Tiny.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/share/perl5/Redis.pm line 18.BEGIN failed--compilation aborted at /usr/local/share/perl5/Redis.pm line 18.Compilation failed in require at a1.pl line 1.BEGIN failed--compilation aborted at a1.pl line 1.我一运行 就包这个错需要安装:test-redis:/root# cpan  Try::Tiny[root@redis01 ~]# perl redis.pl Can't locate Time/HiRes.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/share/perl5/Redis.pm line 405.[root@redis01 ~]# yum install perl-Time-HiRes6.redis 连接不上会报错:test-redis:/root# cat a1.pl use Redis;my $setRedis = Redis->new( server => "192.168.32.168:6379",reconnect => 1,every=>60);test-redis:/root# perl a1.plCould not connect to Redis server at 192.168.32.168:6379: No route to host at /usr/local/share/perl5/Redis.pm line 423Redis::__build_sock('Redis=HASH(0x1b4a250)') called at /usr/local/share/perl5/Redis.pm line 410eval {...} called at /usr/local/share/perl5/Redis.pm line 410Redis::__connect('Redis=HASH(0x1b4a250)') called at /usr/local/share/perl5/Redis.pm line 68Redis::new('Redis', 'server', '192.168.32.168:6379', 'reconnect', 1, 'every', 60) called at a1.pl line 2...propagated at /usr/local/share/perl5/Redis.pm line 413.192.168.32.167 上没有redis服务密码认证:127.0.0.1:6379> auth 'r,uLgt.313'OK127.0.0.1:6379> auth  'r,uLgt.313'OK127.0.0.1:6379> get name(nil)127.0.0.1:6379> set name ww2OK127.0.0.1:6379> get name"ww2"127.0.0.1:6379> saveOKset --set(key, value):给数据库中名称为key的string赋予值valuget ---取值save 保存use Redis;my $r = Redis->new( server => "192.168.32.167:6379",reconnect => 1,every=>60); $r = Redis->new( password =>  'r,uLgt.313' );  $r->set('wangpin','147258369');  $r->save;  $r->quit;


                                             
0 0
原创粉丝点击