-
-
Save sci-phi/4264703 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "relix" | |
gem "ruby-progressbar" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: https://rubygems.org/ | |
specs: | |
hiredis (0.4.5) | |
redis (3.0.2) | |
relix (1.3.0) | |
hiredis (~> 0.4.1) | |
redis (~> 3.0) | |
ruby-progressbar (1.0.2) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
relix | |
ruby-progressbar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "relix" | |
class IndexedFile | |
include Relix | |
Relix.port = "8765" | |
relix do | |
primary_key :path | |
multi :extension | |
ordered :size | |
ordered :ctime | |
unique :ino | |
end | |
attr_reader :path | |
def initialize(path) | |
@path = path | |
end | |
def size | |
stat.size | |
end | |
def ctime | |
stat.ctime | |
end | |
def ino | |
stat.ino | |
end | |
def stat | |
@stat ||= ::File.stat(path) | |
end | |
def extension | |
extension = ::File.extname(path) | |
if extension | |
if extension != "" | |
extension[1..-1] | |
else | |
nil | |
end | |
else | |
nil | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
$: << File.expand_path("..", __FILE__) | |
require "indexed_file" | |
require "ruby-progressbar" | |
target = File.expand_path(ARGV[0] || abort("Usage: #{$0} <DIRECTORY>")) | |
abort("Unable to find target directory") unless(File.exist?(target)) | |
abort("Target must be a directory") unless(File.directory?(target)) | |
def each_file_in(target, &block) | |
Dir["#{target}/*"].each do |file| | |
next if File.symlink?(file) | |
yield(file) | |
if File.directory?(file) | |
each_file_in(file, &block) | |
end | |
end | |
end | |
def index(target) | |
count = 0; each_file_in(target){count += 1} | |
progress = ProgressBar.create( | |
title: "Indexing", | |
total: count, | |
format: "%c %t: %p%% <%B> %e %a") | |
each_file_in(target) do |file| | |
IndexedFile.new(file).index! | |
progress.increment | |
end | |
progress.finish unless progress.finished? | |
end | |
index(target) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
daemonize no | |
port 8765 | |
timeout 300 | |
loglevel warning | |
logfile stdout | |
databases 1 | |
appendonly no | |
vm-enabled no | |
hash-max-zipmap-entries 64 | |
hash-max-zipmap-value 512 | |
activerehashing no |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
redis-server redis.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment