bastos (owner)

Revisions

gist: 65170 Download_button fork
public
Description:
Test Memcached
Public Clone URL: git://gist.github.com/65170.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'rubygems'
require 'memcache'
 
memcache_options = {
  :namespace => 'agp:test:key',
  :multithread => true
}
 
memcached_servers = [ ENV['MEMCACHED_LOCATION'] || '0.0.0.0:12211']
 
# Cache configurations. You can force the use of pure ruby memcache lib.
cache_params = *([memcached_servers, memcache_options].flatten)
CACHE = MemCache.new memcache_options
CACHE.servers = memcached_servers
 
ths = []
 
100.times do |i|
  ths << Thread.new do
    CACHE.set "k#{i}","#{Time.now.to_f}-#{i}-value"
    CACHE.get "k#{i}"
  end
end
 
ths.each{|t| t.join}
puts ths.size
puts "END"