[root@mysql ~]# yum install redis
Loaded plugins: fastestmirror
Determining fastest mirrors
Exiting on user cancel
[root@mysql ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done.
[ OK ]
[root@mysql ~]# yum install redis
Loaded plugins: fastestmirror
Determining fastest mirrors
* addons: mirrors.yun-idc.com
* base: mirrors.yun-idc.com
* extras: mirror.esocc.com
* updates: mirrors.yun-idc.com
addons | 1.9 kB 00:00
base | 1.1 kB 00:00
extras | 2.1 kB 00:00
extras/primary_db | 167 kB 00:00
updates | 1.9 kB 00:00
updates/primary_db | 503 kB 00:03
Setting up Install Process
No package redis available.
Nothing to do
[root@mysql ~]# rpm -ivh http://dl.Fedoraproject.org/pub/ ... ease-5-4.noarch.rpm
Retrieving http://dl.Fedoraproject.org/pub/
/var/tmp/rpm-xfer.R5oV1p: not an rpm package (or package manifest):
[root@mysql ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
warning: /var/tmp/rpm-xfer.JfhQhy: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
[root@mysql ~]# yum install redis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: mirrors.grandcloud.cn
* base: mirrors.grandcloud.cn
* epel: mirrors.yun-idc.com
* extras: mirrors.grandcloud.cn
* updates: mirrors.grandcloud.cn
epel | 3.6 kB 00:00
epel/primary_db | 3.1 MB 00:13
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package redis.i386 0:2.4.10-1.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
redis i386 2.4.10-1.el5 epel 299 k
Transaction Summary
================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 299 k
Is this ok [y/N]: y
Downloading Packages:
redis-2.4.10-1.el5.i386.rpm | 299 kB 00:02
warning: rpmts_HdrFromFdno: Header V4 DSA signature: NOKEY, key ID 217521f6
epel/gpgkey | 1.7 kB 00:00
Importing GPG key 0x217521F6 "Fedora EPEL <[email protected]>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : redis 1/1
Installed:
redis.i386 0:2.4.10-1.el5
Complete!
[root@mysql ~]
[root@mysql ~]# find / -name "redis*"
/usr/share/doc/redis-2.4.10
/usr/bin/redis-check-dump
/usr/bin/redis-benchmark
/usr/bin/redis-cli
/usr/bin/redis-check-aof
/usr/sbin/redis-server
/etc/redis.conf
/etc/logrotate.d/redis
/etc/rc.d/init.d/redis
/var/run/redis
/var/lib/redis
/var/log/redis
[root@mysql ~]#
[root@mysql ~]# ps aux|grep redis
root 4148 0.0 0.2 31056 1088 ? Ssl 22:44 0:00 redis-server /etc/redis.conf
root 4153 0.0 0.1 4008 668 pts/2 R+ 22:44 0:00 grep redis
[root@mysql ~]# telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
set song 8
+OK
get song
$1
8
set xixi
-ERR wrong number of arguments for 'set' command
get ^H
$-1
set song xi
+OK
get xi
$-1
get song
$2
xi
lpush 11 11 ^H
:2
lpush 11 22
:3
rpush 55 66
:1
lrange 11 0 -1
*3
$2
22
$1
$2
11
s
-ERR unknown command 's'
del 33
:0
lrange 11 0 -1
*3
$2
22
$1
$2
11
quit
+OK
Connection closed by foreign host.
[root@mysql ~]#
Ruby連接Redis數據庫測試
1.下載ruby程序包
[root@mysql ~]# rpm -qa | grep ruby
[root@mysql ~]#
[root@mysql ~]# mkdir ruby
[root@mysql ~]# cd ruby/
[root@mysql ruby]# pwd
/root/ruby
[root@mysql ruby]# wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p180.tar.gz
--2013-07-01 22:49:15-- http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p180.tar.gz
Resolving ftp.ruby-lang.org... 221.186.184.68
Connecting to ftp.ruby-lang.org|221.186.184.68|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11158935 (11M) [application/x-tar]
Saving to: `ruby-1.9.2-p180.tar.gz'
100%[======================================>] 11,158,935 52.6K/s in 3m 30s
2013-07-01 22:52:47 (51.8 KB/s) - `ruby-1.9.2-p180.tar.gz' saved [11158935/11158935]
[root@mysql ruby]#
tar -zxvf ruby-1.9.2-p180.tar.gz
[root@mysql ruby]# cd ruby-1.9.2-p180
[root@mysql ruby-1.9.2-p180]# ./configure
checking whether ELF binaries are produced... yes
checking whether OS depend dynamic link works... yes
checking pthread.h usability... yes
checking pthread.h presence... yes
checking for pthread.h... yes
checking for if make is GNU make... yes
checking for nroff... /usr/bin/nroff
.ext/include/i686-linux/ruby/config.h updated
ruby library version = 1.9.1
configure: creating ./config.status
config.status: creating Makefile
[root@mysql ruby-1.9.2-p180]# make
Generating RI...
Files: 515
Classes: 1087 ( 654 undocumented)
Constants: 1364 ( 1141 undocumented)
Modules: 239 ( 137 undocumented)
Methods: 7642 ( 2876 undocumented)
53.46% documented
Elapsed: 87.4s
[root@mysql ruby-1.9.2-p180]# make install
installing extension scripts: /usr/local/lib/ruby/site_ruby/1.9.1
installing extension scripts: /usr/local/lib/ruby/vendor_ruby/1.9.1
installing extension headers: /usr/local/include/ruby-1.9.1/ruby
installing rdoc: /usr/local/share/ri/1.9.1/system
installing capi-docs: /usr/local/share/doc/ruby
installing command scripts: /usr/local/bin
installing library scripts: /usr/local/lib/ruby/1.9.1
installing common headers: /usr/local/include/ruby-1.9.1
installing manpages: /usr/local/share/man/man1
installing default gems: /usr/local/lib/ruby/gems/1.9.1 (cache, doc, gems, specifications)
rake 0.8.7
rdoc 2.5.8
minitest 1.6.0
[root@mysql ruby-1.9.2-p180]#
找ruby安裝到哪些目錄下
[root@mysql ruby-1.9.2-p180]# find / -name ruby
/usr/local/include/ruby-1.9.1/i686-linux/ruby
/usr/local/include/ruby-1.9.1/ruby
/usr/local/share/doc/ruby
/usr/local/lib/ruby
/usr/local/bin/ruby
/root/ruby
/root/ruby/ruby-1.9.2-p180/.ext/include/i686-linux/ruby
/root/ruby/ruby-1.9.2-p180/.ext/include/ruby
/root/ruby/ruby-1.9.2-p180/include/ruby
/root/ruby/ruby-1.9.2-p180/ruby
/root/ruby/ruby-1.9.2-p180/test/ruby
[root@mysql ruby-1.9.2-p180]#
設置/etc/profile環境變量,對全局有效
[root@mysql ruby]# export PATH=/usr/local/bin
[root@mysql ruby]# export PATH=/usr/local/bin:/sbin:$PATH
安裝rubygems組件(通過這個組件安裝redis-rb程序庫)
[root@mysql ruby-1.9.2-p180]# yum install rubygems
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: mirrors.grandcloud.cn
* base: mirrors.grandcloud.cn
* epel: mirrors.yun-idc.com
* extras: mirrors.grandcloud.cn
* updates: mirrors.grandcloud.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package rubygems.noarch 0:1.3.1-1.el5 set to be updated
--> Processing Dependency: ruby(abi) = 1.8 for package: rubygems
--> Processing Dependency: ruby-rdoc for package: rubygems
--> Processing Dependency: /usr/bin/ruby for package: rubygems
--> Running transaction check
---> Package ruby.i386 0:1.8.5-29.el5_9 set to be updated
---> Package ruby-libs.i386 0:1.8.5-29.el5_9 set to be updated
---> Package ruby-rdoc.i386 0:1.8.5-29.el5_9 set to be updated
--> Processing Dependency: ruby-irb = 1.8.5-29.el5_9 for package: ruby-rdoc
--> Running transaction check
---> Package ruby-irb.i386 0:1.8.5-29.el5_9 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
rubygems noarch 1.3.1-1.el5 epel 177 k
Installing for dependencies:
ruby i386 1.8.5-29.el5_9 updates 279 k
ruby-irb i386 1.8.5-29.el5_9 updates 71 k
ruby-libs i386 1.8.5-29.el5_9 updates 1.6 M
ruby-rdoc i386 1.8.5-29.el5_9 updates 137 k
Transaction Summary
================================================================================
Install 5 Package(s)
Upgrade 0 Package(s)
Total download size: 2.3 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): ruby-irb-1.8.5-29.el5_9.i386.rpm | 71 kB 00:01
(2/5): ruby-rdoc-1.8.5-29.el5_9.i386.rpm | 137 kB 00:00
(3/5): rubygems-1.3.1-1.el5.noarch.rpm | 177 kB 00:01
(4/5): ruby-1.8.5-29.el5_9.i386.rpm | 279 kB 00:01
(5/5): ruby-libs-1.8.5-29.el5_9.i386.rpm | 1.6 MB 00:22
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 83 kB/s | 2.3 MB 00:28
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : ruby-libs 1/5
Installing : ruby 2/5
Installing : ruby-irb 3/5
Installing : ruby-rdoc 4/5
Installing : rubygems 5/5
Installed:
rubygems.noarch 0:1.3.1-1.el5
Dependency Installed:
ruby.i386 0:1.8.5-29.el5_9 ruby-irb.i386 0:1.8.5-29.el5_9 ruby-libs.i386 0:1.8.5-29.el5_9 ruby-rdoc.i386 0:1.8.5-29.el5_9
Complete!
[root@mysql ruby-1.9.2-p180]#
編寫ruby腳本訪問redis數據庫
[root@mysql ruby]# vim song_redis.rb
require 'rubygems'
require 'redis'
redis=Redis.new
redis2=Redis.new
hoge = "leonarding";
redis.lpush:hoge,3
redis.lpush:hoge,2
redis.lpush:hoge,1
redis.rpush:hoge,4
p redis.lrange:hoge,0,-1
~
~
~
~
~
~
~
~
~
~
~
~
~
"song_redis.rb" 10L, 197C written
[root@mysql ruby]#
[root@mysql ruby]# ruby song_redis.rb
["1", "2", "3", "4"]
[root@mysql ruby]#
[root@mysql ruby]# ruby song_redis.rb
["1", "2", "3", "1", "2", "3", "4", "4"]
[root@mysql ruby]#
[root@mysql ruby]# ruby song_redis.rb
["1", "2", "3", "1", "2", "3", "1", "2", "3", "4", "4", "4"]
[root@mysql ruby]#
redis的基礎學習
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
[015]Redis | 常用命令key管理
GC怪兽
2020-05-25 22:51:51
redis5.0.9哨兵模式redis-sentinel
hanye韓也
2020-05-25 17:31:59
redis下的cluster的配置安裝
hanye韓也
2018-09-11 05:34:30
redis緩存tomcat
hanye韓也
2018-09-11 05:34:30
redis下的cluste的腳本監控
hanye韓也
2018-09-11 05:34:29