יום ראשון, 26 במאי 2013

Redis Simple

loading the Radis local server :
zvika@ubuntu:~$ redis-server

Check if the Redis Server is alive :
zvika@ubuntu:~$ redis-cli ping
PONG

Simple get set  commands to redis in redis client shell

zvika@ubuntu:~$ redis-cli
redis 127.0.0.1:6379> set myName Zvika
OK
redis 127.0.0.1:6379> get myName 
"Zvika"
redis 127.0.0.1:6379> 

Use the Radis RB as interface between Radis and Ruby
https://github.com/redis/redis-rb

Print
Ruby default require path:
ruby -e 'puts $:' 

Simple Ruby program that’s interacts with Redis


require 'rubygems'
require 'redis'
require 'json'
r = Redis.new
#Check if Radis server is alive
puts  (r.ping)
#Simple Set Get operation 
r.set('Age','42')
puts (r.get('Age'))
#Use Json lib in order to convert form json to string 
#and the oposite direction 
r.set "Data", {'Family'=>'Peer'}.to_json
theJasonObject = JSON.load (r.get('Data'))
puts (theJasonObject['Family'])

אין תגובות:

הוסף רשומת תגובה