Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

clean unused files

  • Loading branch information...
commit 61f221cb172d055ee2120f4b05ddc56f2ec3748f 1 parent 19ea2ff
@steveyen authored
Showing with 0 additions and 329 deletions.
  1. +0 −92 redis.conf
  2. +0 −237 rubyredis.rb
View
92 redis.conf
@@ -1,92 +0,0 @@
-# Redis configuration file example
-
-# By default Redis does not run as a daemon. Use 'yes' if you need it.
-# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
-daemonize no
-
-# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
-# You can specify a custom pid file location here.
-pidfile /var/run/redis.pid
-
-# Accept connections on the specified port, default is 6379
-port 6379
-
-# If you want you can bind a single interface, if the bind option is not
-# specified all the interfaces will listen for connections.
-#
-# bind 127.0.0.1
-
-# Close the connection after a client is idle for N seconds (0 to disable)
-timeout 300
-
-# Save the DB on disk:
-#
-# save <seconds> <changes>
-#
-# Will save the DB if both the given number of seconds and the given
-# number of write operations against the DB occurred.
-#
-# In the example below the behaviour will be to save:
-# after 900 sec (15 min) if at least 1 key changed
-# after 300 sec (5 min) if at least 10 keys changed
-# after 60 sec if at least 10000 keys changed
-save 10 1
-save 5 10
-save 1 10000
-
-# The filename where to dump the DB
-dbfilename dump.rdb
-
-# For default save/load DB in/from the working directory
-# Note that you must specify a directory not a file name.
-dir ./
-
-# Set server verbosity to 'debug'
-# it can be one of:
-# debug (a lot of information, useful for development/testing)
-# notice (moderately verbose, what you want in production probably)
-# warning (only very important / critical messages are logged)
-loglevel debug
-
-# Specify the log file name. Also 'stdout' can be used to force
-# the demon to log on the standard output. Note that if you use standard
-# output for logging but daemonize, logs will be sent to /dev/null
-logfile stdout
-
-# Set the number of databases. The default database is DB 0, you can select
-# a different one on a per-connection basis using SELECT <dbid> where
-# dbid is a number between 0 and 'databases'-1
-databases 16
-
-################################# REPLICATION #################################
-
-# Master-Slave replication. Use slaveof to make a Redis instance a copy of
-# another Redis server. Note that the configuration is local to the slave
-# so for example it is possible to configure the slave to save the DB with a
-# different interval, or to listen to another port, and so on.
-
-# slaveof <masterip> <masterport>
-
-################################## SECURITY ###################################
-
-# Require clients to issue AUTH <PASSWORD> before processing any other
-# commands. This might be useful in environments in which you do not trust
-# others with access to the host running redis-server.
-#
-# This should stay commented out for backward compatibility and because most
-# people do not need auth (e.g. they run their own servers).
-
-# requirepass foobared
-
-############################### ADVANCED CONFIG ###############################
-
-# Glue small output buffers together in order to send small replies in a
-# single TCP packet. Uses a bit more CPU but most of the times it is a win
-# in terms of number of queries per second. Use 'yes' if unsure.
-glueoutputbuf yes
-
-# Use object sharing. Can save a lot of memory if you have many common
-# string in your dataset, but performs lookups against the shared objects
-# pool so it uses more CPU and can be a bit slower. Usually it's a good
-# idea.
-shareobjects no
View
237 rubyredis.rb
@@ -1,237 +0,0 @@
-# RubyRedis is an alternative implementatin of Ruby client library written
-# by Salvatore Sanfilippo.
-#
-# The aim of this library is to create an alternative client library that is
-# much simpler and does not implement every command explicitly but uses
-# method_missing instead.
-
-require 'socket'
-require 'set'
-
-begin
- if (RUBY_VERSION >= '1.9')
- require 'timeout'
- RedisTimer = Timeout
- else
- require 'system_timer'
- RedisTimer = SystemTimer
- end
-rescue LoadError
- RedisTimer = nil
-end
-
-class RedisClient
- BulkCommands = {
- "set"=>true, "setnx"=>true, "rpush"=>true, "lpush"=>true, "lset"=>true,
- "lrem"=>true, "sadd"=>true, "srem"=>true, "sismember"=>true,
- "echo"=>true, "getset"=>true, "smove"=>true
- }
-
- ConvertToBool = lambda{|r| r == 0 ? false : r}
-
- ReplyProcessor = {
- "exists" => ConvertToBool,
- "sismember"=> ConvertToBool,
- "sadd"=> ConvertToBool,
- "srem"=> ConvertToBool,
- "smove"=> ConvertToBool,
- "move"=> ConvertToBool,
- "setnx"=> ConvertToBool,
- "del"=> ConvertToBool,
- "renamenx"=> ConvertToBool,
- "expire"=> ConvertToBool,
- "keys" => lambda{|r| r.split(" ")},
- "info" => lambda{|r|
- info = {}
- r.each_line {|kv|
- k,v = kv.split(":",2).map{|x| x.chomp}
- info[k.to_sym] = v
- }
- info
- }
- }
-
- Aliases = {
- "flush_db" => "flushdb",
- "flush_all" => "flushall",
- "last_save" => "lastsave",
- "key?" => "exists",
- "delete" => "del",
- "randkey" => "randomkey",
- "list_length" => "llen",
- "push_tail" => "rpush",
- "push_head" => "lpush",
- "pop_tail" => "rpop",
- "pop_head" => "lpop",
- "list_set" => "lset",
- "list_range" => "lrange",
- "list_trim" => "ltrim",
- "list_index" => "lindex",
- "list_rm" => "lrem",
- "set_add" => "sadd",
- "set_delete" => "srem",
- "set_count" => "scard",
- "set_member?" => "sismember",
- "set_members" => "smembers",
- "set_intersect" => "sinter",
- "set_intersect_store" => "sinterstore",
- "set_inter_store" => "sinterstore",
- "set_union" => "sunion",
- "set_union_store" => "sunionstore",
- "set_diff" => "sdiff",
- "set_diff_store" => "sdiffstore",
- "set_move" => "smove",
- "set_unless_exists" => "setnx",
- "rename_unless_exists" => "renamenx"
- }
-
- def initialize(opts={})
- @host = opts[:host] || '127.0.0.1'
- @port = opts[:port] || 6379
- @db = opts[:db] || 0
- @timeout = opts[:timeout] || 0
- connect_to_server
- end
-
- def to_s
- "Redis Client connected to #{@host}:#{@port} against DB #{@db}"
- end
-
- def connect_to_server
- @sock = connect_to(@host,@port,@timeout == 0 ? nil : @timeout)
- call_command(["select",@db]) if @db != 0
- end
-
- def connect_to(host, port, timeout=nil)
- # We support connect() timeout only if system_timer is availabe
- # or if we are running against Ruby >= 1.9
- # Timeout reading from the socket instead will be supported anyway.
- if @timeout != 0 and RedisTimer
- begin
- sock = TCPSocket.new(host, port, 0)
- rescue Timeout::Error
- @sock = nil
- raise Timeout::Error, "Timeout connecting to the server"
- end
- else
- sock = TCPSocket.new(host, port, 0)
- end
-
- # If the timeout is set we set the low level socket options in order
- # to make sure a blocking read will return after the specified number
- # of seconds. This hack is from memcached ruby client.
- if timeout
- secs = Integer(timeout)
- usecs = Integer((timeout - secs) * 1_000_000)
- optval = [secs, usecs].pack("l_2")
- sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
- sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
- end
- sock
- end
-
- def method_missing(*argv)
- call_command(argv)
- end
-
- def call_command(argv)
- # this wrapper to raw_call_command handle reconnection on socket
- # error. We try to reconnect just one time, otherwise let the error
- # araise.
- connect_to_server if !@sock
- begin
- raw_call_command(argv)
- rescue Errno::ECONNRESET
- @sock.close
- connect_to_server
- raw_call_command(argv)
- end
- end
-
- def raw_call_command(argv)
- bulk = nil
- argv[0] = argv[0].to_s.downcase
- argv[0] = Aliases[argv[0]] if Aliases[argv[0]]
- if BulkCommands[argv[0]]
- bulk = argv[-1].to_s
- argv[-1] = bulk.length
- end
- @sock.write(argv.join(" ")+"\r\n")
- @sock.write(bulk+"\r\n") if bulk
-
- # Post process the reply if needed
- processor = ReplyProcessor[argv[0]]
- processor ? processor.call(read_reply) : read_reply
- end
-
- def select(*args)
- raise "SELECT not allowed, use the :db option when creating the object"
- end
-
- def [](key)
- get(key)
- end
-
- def []=(key,value)
- set(key,value)
- end
-
- def sort(key, opts={})
- cmd = []
- cmd << "SORT #{key}"
- cmd << "BY #{opts[:by]}" if opts[:by]
- cmd << "GET #{[opts[:get]].flatten * ' GET '}" if opts[:get]
- cmd << "#{opts[:order]}" if opts[:order]
- cmd << "LIMIT #{opts[:limit].join(' ')}" if opts[:limit]
- call_command(cmd)
- end
-
- def incr(key,increment=nil)
- call_command(increment ? ["incrby",key,increment] : ["incr",key])
- end
-
- def decr(key,decrement=nil)
- call_command(decrement ? ["decrby",key,decrement] : ["decr",key])
- end
-
- def read_reply
- # We read the first byte using read() mainly because gets() is
- # immune to raw socket timeouts.
- begin
- rtype = @sock.read(1)
- rescue Errno::EAGAIN
- # We want to make sure it reconnects on the next command after the
- # timeout. Otherwise the server may reply in the meantime leaving
- # the protocol in a desync status.
- @sock = nil
- raise Errno::EAGAIN, "Timeout reading from the socket"
- end
-
- raise Errno::ECONNRESET,"Connection lost" if !rtype
- line = @sock.gets
- case rtype
- when "-"
- raise "-"+line.strip
- when "+"
- line.strip
- when ":"
- line.to_i
- when "$"
- bulklen = line.to_i
- return nil if bulklen == -1
- data = @sock.read(bulklen)
- @sock.read(2) # CRLF
- data
- when "*"
- objects = line.to_i
- return nil if bulklen == -1
- res = []
- objects.times {
- res << read_reply
- }
- res
- else
- raise "Protocol error, got '#{rtype}' as initial reply byte"
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.