moneta 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rspec +4 -0
- data/.travis.yml +83 -32
- data/.yardopts +6 -1
- data/CHANGES +30 -0
- data/CONTRIBUTORS +4 -0
- data/Gemfile +28 -36
- data/LICENSE +1 -1
- data/README.md +136 -67
- data/SPEC.md +70 -0
- data/feature_matrix.yaml +235 -0
- data/lib/active_support/cache/moneta_store.rb +102 -6
- data/lib/moneta.rb +9 -2
- data/lib/moneta/adapters/activerecord.rb +258 -98
- data/lib/moneta/adapters/activesupportcache.rb +133 -0
- data/lib/moneta/adapters/cassandra.rb +290 -44
- data/lib/moneta/adapters/client.rb +11 -2
- data/lib/moneta/adapters/couch.rb +179 -25
- data/lib/moneta/adapters/datamapper.rb +1 -0
- data/lib/moneta/adapters/daybreak.rb +21 -4
- data/lib/moneta/adapters/dbm.rb +7 -7
- data/lib/moneta/adapters/file.rb +11 -1
- data/lib/moneta/adapters/gdbm.rb +7 -7
- data/lib/moneta/adapters/kyotocabinet.rb +66 -1
- data/lib/moneta/adapters/leveldb.rb +27 -1
- data/lib/moneta/adapters/lmdb.rb +29 -1
- data/lib/moneta/adapters/lruhash.rb +30 -0
- data/lib/moneta/adapters/memcached/dalli.rb +50 -5
- data/lib/moneta/adapters/memcached/native.rb +11 -4
- data/lib/moneta/adapters/memory.rb +2 -0
- data/lib/moneta/adapters/mongo/base.rb +32 -7
- data/lib/moneta/adapters/mongo/moped.rb +59 -2
- data/lib/moneta/adapters/mongo/official.rb +40 -0
- data/lib/moneta/adapters/pstore.rb +56 -8
- data/lib/moneta/adapters/redis.rb +79 -19
- data/lib/moneta/adapters/sdbm.rb +7 -7
- data/lib/moneta/adapters/sequel.rb +440 -39
- data/lib/moneta/adapters/sqlite.rb +74 -10
- data/lib/moneta/adapters/tdb.rb +16 -1
- data/lib/moneta/adapters/tokyocabinet.rb +7 -1
- data/lib/moneta/adapters/tokyotyrant.rb +22 -0
- data/lib/moneta/cache.rb +11 -1
- data/lib/moneta/expires.rb +110 -8
- data/lib/moneta/lock.rb +21 -2
- data/lib/moneta/mixins.rb +279 -3
- data/lib/moneta/pool.rb +15 -6
- data/lib/moneta/proxy.rb +46 -2
- data/lib/moneta/server.rb +5 -1
- data/lib/moneta/shared.rb +27 -11
- data/lib/moneta/stack.rb +1 -1
- data/lib/moneta/synchronize.rb +2 -8
- data/lib/moneta/transformer.rb +152 -2
- data/lib/moneta/transformer/config.rb +2 -0
- data/lib/moneta/transformer/helper.rb +2 -2
- data/lib/moneta/version.rb +1 -1
- data/lib/moneta/weak_each_key.rb +74 -0
- data/lib/moneta/wrapper.rb +25 -0
- data/moneta.gemspec +2 -2
- data/script/benchmarks +174 -62
- data/script/parallel-tests +58 -83
- data/script/start-hbase +46 -0
- data/script/start-services +9 -2
- data/script/update-feature-matrix +148 -0
- data/spec/active_support/cache_moneta_store_spec.rb +132 -109
- data/spec/features/concurrent_create.rb +21 -0
- data/spec/features/concurrent_increment.rb +32 -0
- data/spec/features/create.rb +25 -0
- data/spec/features/create_expires.rb +19 -0
- data/spec/features/default_expires.rb +15 -0
- data/spec/features/each_key.rb +119 -0
- data/spec/features/expires.rb +291 -0
- data/spec/features/features.rb +16 -0
- data/spec/features/increment.rb +98 -0
- data/spec/features/marshallable_key.rb +43 -0
- data/spec/features/marshallable_value.rb +7 -0
- data/spec/features/multiprocess.rb +8 -0
- data/spec/features/not_create.rb +7 -0
- data/spec/features/not_each_key.rb +7 -0
- data/spec/features/not_increment.rb +13 -0
- data/spec/features/not_persist.rb +9 -0
- data/spec/features/null.rb +66 -0
- data/spec/features/persist.rb +14 -0
- data/spec/features/returndifferent.rb +9 -0
- data/spec/features/returnsame.rb +9 -0
- data/spec/features/store.rb +261 -0
- data/spec/features/store_large.rb +13 -0
- data/spec/features/transform_value.rb +44 -0
- data/spec/features/transform_value_expires.rb +41 -0
- data/spec/helper.rb +391 -74
- data/spec/moneta/adapters/activerecord/adapter_activerecord_existing_connection_spec.rb +59 -0
- data/spec/moneta/adapters/activerecord/adapter_activerecord_spec.rb +118 -0
- data/spec/moneta/adapters/activerecord/standard_activerecord_spec.rb +18 -0
- data/spec/moneta/adapters/activerecord/standard_activerecord_with_expires_spec.rb +24 -0
- data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_spec.rb +51 -0
- data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_with_default_expires_spec.rb +51 -0
- data/spec/moneta/adapters/cassandra/adapter_cassandra_spec.rb +17 -0
- data/spec/moneta/adapters/cassandra/adapter_cassandra_with_default_expires_spec.rb +18 -0
- data/spec/moneta/adapters/cassandra/helper.rb +18 -0
- data/spec/moneta/adapters/cassandra/standard_cassandra_spec.rb +18 -0
- data/spec/moneta/adapters/client/adapter_client_spec.rb +11 -0
- data/spec/moneta/adapters/client/standard_client_tcp_spec.rb +23 -0
- data/spec/moneta/adapters/client/standard_client_unix_spec.rb +12 -0
- data/spec/moneta/adapters/cookie/adapter_cookie_spec.rb +7 -0
- data/spec/moneta/adapters/couch/adapter_couch_spec.rb +7 -0
- data/spec/moneta/adapters/couch/standard_couch_spec.rb +9 -0
- data/spec/moneta/adapters/couch/standard_couch_with_expires_spec.rb +13 -0
- data/spec/moneta/adapters/datamapper/adapter_datamapper_spec.rb +43 -0
- data/spec/moneta/adapters/datamapper/standard_datamapper_spec.rb +21 -0
- data/spec/moneta/adapters/datamapper/standard_datamapper_with_expires_spec.rb +26 -0
- data/spec/moneta/adapters/datamapper/standard_datamapper_with_repository_spec.rb +22 -0
- data/spec/moneta/adapters/daybreak/adapter_daybreak_spec.rb +7 -0
- data/spec/moneta/adapters/daybreak/standard_daybreak_spec.rb +7 -0
- data/spec/moneta/adapters/daybreak/standard_daybreak_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/dbm/adapter_dbm_spec.rb +7 -0
- data/spec/moneta/adapters/dbm/standard_dbm_spec.rb +7 -0
- data/spec/moneta/adapters/dbm/standard_dbm_with_expires_spec.rb +12 -0
- data/spec/moneta/adapters/file/adapter_file_spec.rb +7 -0
- data/spec/moneta/adapters/file/standard_file_spec.rb +7 -0
- data/spec/moneta/adapters/file/standard_file_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/fog/adapter_fog_spec.rb +16 -0
- data/spec/moneta/adapters/fog/standard_fog_spec.rb +15 -0
- data/spec/moneta/adapters/fog/standard_fog_with_expires_spec.rb +20 -0
- data/spec/moneta/adapters/gdbm/adapter_gdbm_spec.rb +7 -0
- data/spec/moneta/adapters/gdbm/standard_gdbm_spec.rb +7 -0
- data/spec/moneta/adapters/gdbm/standard_gdbm_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/hashfile/standard_hashfile_spec.rb +7 -0
- data/spec/moneta/adapters/hashfile/standard_hashfile_with_expires_spec.rb +12 -0
- data/spec/moneta/adapters/hbase/adapter_hbase_spec.rb +7 -0
- data/spec/moneta/adapters/hbase/standard_hbase_spec.rb +4 -0
- data/spec/moneta/adapters/hbase/standard_hbase_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/kyotocabinet/adapter_kyotocabinet_spec.rb +7 -0
- data/spec/moneta/adapters/kyotocabinet/standard_kyotocabinet_spec.rb +7 -0
- data/spec/moneta/adapters/kyotocabinet/standard_kyotocabinet_with_expires_spec.rb +14 -0
- data/spec/moneta/adapters/leveldb/adapter_leveldb_spec.rb +7 -0
- data/spec/moneta/adapters/leveldb/standard_leveldb_spec.rb +7 -0
- data/spec/moneta/adapters/leveldb/standard_leveldb_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/lmdb/adapter_lmdb_spec.rb +7 -0
- data/spec/moneta/adapters/lmdb/adapter_lmdb_with_db_spec.rb +7 -0
- data/spec/moneta/adapters/lmdb/standard_lmdb_spec.rb +7 -0
- data/spec/moneta/adapters/lmdb/standard_lmdb_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/localmemcache/adapter_localmemcache_spec.rb +7 -0
- data/spec/moneta/adapters/localmemcache/standard_localmemcache_spec.rb +7 -0
- data/spec/moneta/adapters/localmemcache/standard_localmemcache_with_expires_spec.rb +11 -0
- data/spec/moneta/{adapter_lruhash_spec.rb → adapters/lruhash/adapter_lruhash_spec.rb} +3 -25
- data/spec/moneta/adapters/lruhash/standard_lruhash_spec.rb +4 -0
- data/spec/moneta/adapters/lruhash/standard_lruhash_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/memcached/adapter_memcached_spec.rb +13 -0
- data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_spec.rb +15 -0
- data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_with_default_expires_spec.rb +15 -0
- data/spec/moneta/adapters/memcached/dalli/standard_memcached_dalli_spec.rb +11 -0
- data/spec/moneta/adapters/memcached/helper.rb +20 -0
- data/spec/moneta/adapters/memcached/native/adapter_memcached_native_spec.rb +15 -0
- data/spec/moneta/adapters/memcached/native/adapter_memcached_native_with_default_expires_spec.rb +15 -0
- data/spec/moneta/adapters/memcached/native/standard_memcached_native_spec.rb +11 -0
- data/spec/moneta/adapters/memcached/standard_memcached_spec.rb +17 -0
- data/spec/moneta/adapters/memory/adapter_memory_spec.rb +7 -0
- data/spec/moneta/adapters/memory/standard_memory_spec.rb +4 -0
- data/spec/moneta/adapters/memory/standard_memory_with_compress_spec.rb +9 -0
- data/spec/moneta/adapters/memory/standard_memory_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/memory/standard_memory_with_json_key_serializer_spec.rb +4 -0
- data/spec/moneta/adapters/memory/standard_memory_with_json_serializer_spec.rb +9 -0
- data/spec/moneta/adapters/memory/standard_memory_with_json_value_serializer_spec.rb +9 -0
- data/spec/moneta/adapters/memory/standard_memory_with_prefix_spec.rb +4 -0
- data/spec/moneta/adapters/memory/standard_memory_with_snappy_compress_spec.rb +9 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_moped_spec.rb +25 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_moped_with_default_expires_spec.rb +12 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_official_spec.rb +25 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_official_with_default_expires_spec.rb +12 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_spec.rb +11 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_with_default_expires_spec.rb +12 -0
- data/spec/moneta/adapters/mongo/standard_mongo_moped_spec.rb +7 -0
- data/spec/moneta/adapters/mongo/standard_mongo_official_spec.rb +7 -0
- data/spec/moneta/adapters/mongo/standard_mongo_spec.rb +7 -0
- data/spec/moneta/adapters/null/null_adapter_spec.rb +7 -0
- data/spec/moneta/adapters/null/standard_null_spec.rb +4 -0
- data/spec/moneta/adapters/pstore/adapter_pstore_spec.rb +7 -0
- data/spec/moneta/adapters/pstore/standard_pstore_spec.rb +9 -0
- data/spec/moneta/adapters/pstore/standard_pstore_with_expires_spec.rb +13 -0
- data/spec/moneta/adapters/redis/adapter_redis_spec.rb +10 -0
- data/spec/moneta/adapters/redis/adapter_redis_with_default_expires_spec.rb +10 -0
- data/spec/moneta/adapters/redis/standard_redis_spec.rb +7 -0
- data/spec/moneta/adapters/restclient/adapter_restclient_spec.rb +11 -0
- data/spec/moneta/adapters/restclient/standard_restclient_spec.rb +10 -0
- data/spec/moneta/adapters/riak/adapter_riak_spec.rb +14 -0
- data/spec/moneta/adapters/riak/standard_riak_spec.rb +10 -0
- data/spec/moneta/adapters/riak/standard_riak_with_expires_spec.rb +10 -0
- data/spec/moneta/adapters/sdbm/adapter_sdbm_spec.rb +7 -0
- data/spec/moneta/adapters/sdbm/standard_sdbm_spec.rb +7 -0
- data/spec/moneta/adapters/sdbm/standard_sdbm_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/sequel/adapter_sequel_spec.rb +181 -0
- data/spec/moneta/adapters/sequel/standard_sequel_spec.rb +14 -0
- data/spec/moneta/adapters/sequel/standard_sequel_with_expires_spec.rb +19 -0
- data/spec/moneta/adapters/sqlite/adapter_sqlite_spec.rb +7 -0
- data/spec/moneta/adapters/sqlite/standard_sqlite_spec.rb +7 -0
- data/spec/moneta/adapters/sqlite/standard_sqlite_with_expires_spec.rb +15 -0
- data/spec/moneta/adapters/tdb/adapter_tdb_spec.rb +7 -0
- data/spec/moneta/adapters/tdb/standard_tdb_spec.rb +7 -0
- data/spec/moneta/adapters/tdb/standard_tdb_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/tokyocabinet/adapter_tokyocabinet_bdb_spec.rb +7 -0
- data/spec/moneta/adapters/tokyocabinet/adapter_tokyocabinet_hdb_spec.rb +7 -0
- data/spec/moneta/adapters/tokyocabinet/standard_tokyocabinet_spec.rb +7 -0
- data/spec/moneta/adapters/tokyocabinet/standard_tokyocabinet_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/tokyotyrant/adapter_tokyotyrant_spec.rb +7 -0
- data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_spec.rb +4 -0
- data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/yaml/adapter_yaml_spec.rb +7 -0
- data/spec/moneta/adapters/yaml/standard_yaml_spec.rb +9 -0
- data/spec/moneta/adapters/yaml/standard_yaml_with_expires_spec.rb +13 -0
- data/spec/moneta/builder_spec.rb +0 -1
- data/spec/moneta/mutex_spec.rb +6 -23
- data/spec/moneta/proxies/cache/cache_file_memory_spec.rb +24 -0
- data/spec/moneta/proxies/cache/cache_memory_null_spec.rb +12 -0
- data/spec/moneta/proxies/expires/expires_file_spec.rb +28 -0
- data/spec/moneta/proxies/expires/expires_memory_spec.rb +15 -0
- data/spec/moneta/proxies/expires/expires_memory_with_default_expires_spec.rb +16 -0
- data/spec/moneta/proxies/lock/lock_spec.rb +10 -0
- data/spec/moneta/{optionmerger_spec.rb → proxies/optionmerger/optionmerger_spec.rb} +2 -18
- data/spec/moneta/proxies/pool/pool_spec.rb +12 -0
- data/spec/moneta/proxies/proxy/proxy_expires_memory_spec.rb +16 -0
- data/spec/moneta/proxies/proxy/proxy_redis_spec.rb +13 -0
- data/spec/moneta/proxies/shared/shared_tcp_spec.rb +49 -0
- data/spec/moneta/proxies/shared/shared_unix_spec.rb +48 -0
- data/spec/moneta/proxies/transformer/transformer_bencode_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_bert_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_bson_spec.rb +23 -0
- data/spec/moneta/proxies/transformer/transformer_bzip2_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_json_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_key_inspect_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_key_marshal_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_key_to_s_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_key_yaml_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_lz4_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_lzma_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_lzo_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_base64_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_city128_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_city32_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_city64_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_escape_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_hex_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_hmac_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_md5_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_md5_spread_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_prefix_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_qp_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_rmd160_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha1_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha256_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha384_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha512_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_truncate_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_urlsafe_base64_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_uuencode_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_msgpack_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_ox_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_php_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_quicklz_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_snappy_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_tnet_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_value_marshal_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_value_yaml_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_yaml_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_zlib_spec.rb +19 -0
- data/spec/moneta/proxies/weak_create/weak_create_spec.rb +21 -0
- data/spec/moneta/proxies/weak_each_key/weak_each_key_spec.rb +24 -0
- data/spec/moneta/proxies/weak_increment/weak_increment_spec.rb +21 -0
- data/spec/moneta/semaphore_spec.rb +6 -23
- data/spec/moneta/stack_file_memory_spec.rb +5 -29
- data/spec/moneta/stack_memory_file_spec.rb +5 -31
- data/spec/quality_spec.rb +1 -1
- data/{spec → test}/action_dispatch/fixtures/session_autoload_test/foo.rb +0 -0
- data/{spec/action_dispatch/session_moneta_store_spec.rb → test/action_dispatch/session_moneta_store_test.rb} +13 -5
- metadata +415 -355
- data/script/generate-specs +0 -2696
- data/spec/moneta/adapter_activerecord_exisiting_connection_spec.rb +0 -36
- data/spec/moneta/adapter_activerecord_spec.rb +0 -65
- data/spec/moneta/adapter_cassandra_spec.rb +0 -33
- data/spec/moneta/adapter_cassandra_with_default_expires_spec.rb +0 -34
- data/spec/moneta/adapter_client_spec.rb +0 -35
- data/spec/moneta/adapter_cookie_spec.rb +0 -30
- data/spec/moneta/adapter_couch_spec.rb +0 -36
- data/spec/moneta/adapter_datamapper_spec.rb +0 -64
- data/spec/moneta/adapter_daybreak_spec.rb +0 -31
- data/spec/moneta/adapter_dbm_spec.rb +0 -31
- data/spec/moneta/adapter_file_spec.rb +0 -34
- data/spec/moneta/adapter_fog_spec.rb +0 -37
- data/spec/moneta/adapter_gdbm_spec.rb +0 -31
- data/spec/moneta/adapter_hbase_spec.rb +0 -33
- data/spec/moneta/adapter_kyotocabinet_spec.rb +0 -31
- data/spec/moneta/adapter_leveldb_spec.rb +0 -31
- data/spec/moneta/adapter_lmdb_spec.rb +0 -32
- data/spec/moneta/adapter_lmdb_with_db_spec.rb +0 -32
- data/spec/moneta/adapter_localmemcache_spec.rb +0 -32
- data/spec/moneta/adapter_memcached_dalli_spec.rb +0 -36
- data/spec/moneta/adapter_memcached_dalli_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_memcached_native_spec.rb +0 -36
- data/spec/moneta/adapter_memcached_native_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_memcached_spec.rb +0 -36
- data/spec/moneta/adapter_memcached_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_memory_spec.rb +0 -184
- data/spec/moneta/adapter_mongo_moped_spec.rb +0 -64
- data/spec/moneta/adapter_mongo_moped_with_default_expires_spec.rb +0 -53
- data/spec/moneta/adapter_mongo_official_spec.rb +0 -64
- data/spec/moneta/adapter_mongo_official_with_default_expires_spec.rb +0 -53
- data/spec/moneta/adapter_mongo_spec.rb +0 -51
- data/spec/moneta/adapter_mongo_with_default_expires_spec.rb +0 -53
- data/spec/moneta/adapter_pstore_spec.rb +0 -250
- data/spec/moneta/adapter_redis_spec.rb +0 -36
- data/spec/moneta/adapter_redis_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_restclient_spec.rb +0 -33
- data/spec/moneta/adapter_riak_spec.rb +0 -36
- data/spec/moneta/adapter_sdbm_spec.rb +0 -30
- data/spec/moneta/adapter_sequel_spec.rb +0 -34
- data/spec/moneta/adapter_sqlite_spec.rb +0 -32
- data/spec/moneta/adapter_tdb_spec.rb +0 -31
- data/spec/moneta/adapter_tokyocabinet_bdb_spec.rb +0 -31
- data/spec/moneta/adapter_tokyocabinet_hdb_spec.rb +0 -31
- data/spec/moneta/adapter_tokyotyrant_spec.rb +0 -34
- data/spec/moneta/adapter_yaml_spec.rb +0 -57
- data/spec/moneta/cache_file_memory_spec.rb +0 -50
- data/spec/moneta/cache_memory_null_spec.rb +0 -35
- data/spec/moneta/expires_file_spec.rb +0 -78
- data/spec/moneta/expires_memory_spec.rb +0 -189
- data/spec/moneta/expires_memory_with_default_expires_spec.rb +0 -190
- data/spec/moneta/lock_spec.rb +0 -187
- data/spec/moneta/null_adapter_spec.rb +0 -86
- data/spec/moneta/pool_spec.rb +0 -38
- data/spec/moneta/proxy_expires_memory_spec.rb +0 -191
- data/spec/moneta/proxy_redis_spec.rb +0 -40
- data/spec/moneta/shared_tcp_spec.rb +0 -46
- data/spec/moneta/shared_unix_spec.rb +0 -46
- data/spec/moneta/standard_activerecord_spec.rb +0 -253
- data/spec/moneta/standard_activerecord_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_cassandra_spec.rb +0 -252
- data/spec/moneta/standard_client_tcp_spec.rb +0 -269
- data/spec/moneta/standard_client_unix_spec.rb +0 -254
- data/spec/moneta/standard_couch_spec.rb +0 -252
- data/spec/moneta/standard_couch_with_expires_spec.rb +0 -254
- data/spec/moneta/standard_datamapper_spec.rb +0 -254
- data/spec/moneta/standard_datamapper_with_expires_spec.rb +0 -256
- data/spec/moneta/standard_datamapper_with_repository_spec.rb +0 -254
- data/spec/moneta/standard_daybreak_spec.rb +0 -250
- data/spec/moneta/standard_daybreak_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_dbm_spec.rb +0 -250
- data/spec/moneta/standard_dbm_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_file_spec.rb +0 -253
- data/spec/moneta/standard_file_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_fog_spec.rb +0 -256
- data/spec/moneta/standard_fog_with_expires_spec.rb +0 -258
- data/spec/moneta/standard_gdbm_spec.rb +0 -250
- data/spec/moneta/standard_gdbm_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_hashfile_spec.rb +0 -253
- data/spec/moneta/standard_hashfile_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_hbase_spec.rb +0 -252
- data/spec/moneta/standard_hbase_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_kyotocabinet_spec.rb +0 -250
- data/spec/moneta/standard_kyotocabinet_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_leveldb_spec.rb +0 -250
- data/spec/moneta/standard_leveldb_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_lmdb_spec.rb +0 -251
- data/spec/moneta/standard_lmdb_with_expires_spec.rb +0 -253
- data/spec/moneta/standard_localmemcache_spec.rb +0 -251
- data/spec/moneta/standard_localmemcache_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_lruhash_spec.rb +0 -187
- data/spec/moneta/standard_lruhash_with_expires_spec.rb +0 -189
- data/spec/moneta/standard_memcached_dalli_spec.rb +0 -255
- data/spec/moneta/standard_memcached_native_spec.rb +0 -255
- data/spec/moneta/standard_memcached_spec.rb +0 -255
- data/spec/moneta/standard_memory_spec.rb +0 -187
- data/spec/moneta/standard_memory_with_compress_spec.rb +0 -187
- data/spec/moneta/standard_memory_with_expires_spec.rb +0 -189
- data/spec/moneta/standard_memory_with_json_key_serializer_spec.rb +0 -86
- data/spec/moneta/standard_memory_with_json_serializer_spec.rb +0 -49
- data/spec/moneta/standard_memory_with_json_value_serializer_spec.rb +0 -90
- data/spec/moneta/standard_memory_with_prefix_spec.rb +0 -187
- data/spec/moneta/standard_memory_with_snappy_compress_spec.rb +0 -187
- data/spec/moneta/standard_mongo_moped_spec.rb +0 -255
- data/spec/moneta/standard_mongo_official_spec.rb +0 -255
- data/spec/moneta/standard_mongo_spec.rb +0 -255
- data/spec/moneta/standard_null_spec.rb +0 -120
- data/spec/moneta/standard_pstore_spec.rb +0 -253
- data/spec/moneta/standard_pstore_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_redis_spec.rb +0 -255
- data/spec/moneta/standard_restclient_spec.rb +0 -252
- data/spec/moneta/standard_riak_spec.rb +0 -255
- data/spec/moneta/standard_riak_with_expires_spec.rb +0 -256
- data/spec/moneta/standard_sdbm_spec.rb +0 -249
- data/spec/moneta/standard_sdbm_with_expires_spec.rb +0 -251
- data/spec/moneta/standard_sequel_spec.rb +0 -253
- data/spec/moneta/standard_sequel_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_sqlite_spec.rb +0 -251
- data/spec/moneta/standard_sqlite_with_expires_spec.rb +0 -253
- data/spec/moneta/standard_tdb_spec.rb +0 -250
- data/spec/moneta/standard_tdb_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_tokyocabinet_spec.rb +0 -250
- data/spec/moneta/standard_tokyocabinet_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_tokyotyrant_spec.rb +0 -253
- data/spec/moneta/standard_tokyotyrant_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_yaml_spec.rb +0 -250
- data/spec/moneta/standard_yaml_with_expires_spec.rb +0 -252
- data/spec/moneta/transformer_bencode_spec.rb +0 -55
- data/spec/moneta/transformer_bert_spec.rb +0 -55
- data/spec/moneta/transformer_bson_spec.rb +0 -60
- data/spec/moneta/transformer_bzip2_spec.rb +0 -55
- data/spec/moneta/transformer_json_spec.rb +0 -55
- data/spec/moneta/transformer_key_inspect_spec.rb +0 -91
- data/spec/moneta/transformer_key_marshal_spec.rb +0 -191
- data/spec/moneta/transformer_key_to_s_spec.rb +0 -91
- data/spec/moneta/transformer_key_yaml_spec.rb +0 -191
- data/spec/moneta/transformer_lz4_spec.rb +0 -55
- data/spec/moneta/transformer_lzma_spec.rb +0 -55
- data/spec/moneta/transformer_lzo_spec.rb +0 -55
- data/spec/moneta/transformer_marshal_base64_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_city128_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_city32_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_city64_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_escape_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_hex_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_hmac_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_md5_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_md5_spread_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_prefix_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_qp_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_rmd160_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha1_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha256_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha384_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha512_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_spec.rb +0 -191
- data/spec/moneta/transformer_marshal_truncate_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_uuencode_spec.rb +0 -194
- data/spec/moneta/transformer_msgpack_spec.rb +0 -55
- data/spec/moneta/transformer_ox_spec.rb +0 -191
- data/spec/moneta/transformer_php_spec.rb +0 -55
- data/spec/moneta/transformer_quicklz_spec.rb +0 -55
- data/spec/moneta/transformer_snappy_spec.rb +0 -55
- data/spec/moneta/transformer_tnet_spec.rb +0 -55
- data/spec/moneta/transformer_value_marshal_spec.rb +0 -191
- data/spec/moneta/transformer_value_yaml_spec.rb +0 -191
- data/spec/moneta/transformer_yaml_spec.rb +0 -191
- data/spec/moneta/transformer_zlib_spec.rb +0 -55
- data/spec/moneta/weak_create_spec.rb +0 -41
- data/spec/moneta/weak_increment_spec.rb +0 -41
- data/spec/monetaspecs.rb +0 -51267
@@ -0,0 +1,133 @@
|
|
1
|
+
module Moneta
|
2
|
+
module Adapters
|
3
|
+
# ActiveSupport::Cache::Store adapter
|
4
|
+
# @api public
|
5
|
+
class ActiveSupportCache
|
6
|
+
include Defaults
|
7
|
+
include ExpiresSupport
|
8
|
+
|
9
|
+
supports :increment
|
10
|
+
|
11
|
+
# @param [Hash] options
|
12
|
+
# @option options [Numeric] :expires default expiration in seconds
|
13
|
+
def initialize(options = {})
|
14
|
+
self.default_expires = options.delete(:expires)
|
15
|
+
@backend =
|
16
|
+
if options[:backend]
|
17
|
+
options[:backend]
|
18
|
+
elsif defined?(Rails)
|
19
|
+
Rails.cache
|
20
|
+
else
|
21
|
+
raise ArgumentError, 'Option :backend is required'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# (see Proxy#key?)
|
26
|
+
def key?(key, options = {})
|
27
|
+
@backend.exist?(key).tap do |exists|
|
28
|
+
if exists && !(expires = expires_value(options, nil)).nil?
|
29
|
+
value = @backend.read(key, options)
|
30
|
+
@backend.write(key, value, options.merge(expires_in: expires ? expires.seconds : nil))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# (see Proxy#load)
|
36
|
+
def load(key, options = {})
|
37
|
+
expires = expires_value(options, nil)
|
38
|
+
value = @backend.read(key, options)
|
39
|
+
if value and !expires.nil?
|
40
|
+
@backend.write(key, value, options.merge(expires_in: expires ? expires.seconds : nil))
|
41
|
+
end
|
42
|
+
if options[:raw]
|
43
|
+
value && value.to_s
|
44
|
+
else
|
45
|
+
value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# (see Proxy#store)
|
50
|
+
def store(key, value, options = {})
|
51
|
+
expires = expires_value(options)
|
52
|
+
@backend.write(key, value, options.merge(expires_in: expires ? expires.seconds : nil))
|
53
|
+
value
|
54
|
+
end
|
55
|
+
|
56
|
+
# (see Proxy#increment)
|
57
|
+
def increment(key, amount = 1, options = {})
|
58
|
+
expires = expires_value(options)
|
59
|
+
options.delete(:raw)
|
60
|
+
existing = Integer(@backend.fetch(key, options.merge(raw: true)) { 0 })
|
61
|
+
if amount > 0
|
62
|
+
@backend.increment(key, amount, options.merge(expires_in: expires ? expires.seconds : nil))
|
63
|
+
elsif amount < 0
|
64
|
+
@backend.decrement(key, -amount, options.merge(expires_in: expires ? expires.seconds : nil))
|
65
|
+
else
|
66
|
+
existing
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# (see Proxy#delete)
|
71
|
+
def delete(key, options = {})
|
72
|
+
value = @backend.read(key, options)
|
73
|
+
if value != nil
|
74
|
+
@backend.delete(key, options)
|
75
|
+
options[:raw] ? value.to_s : value
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# (see Proxy#clear)
|
80
|
+
def clear(options = {})
|
81
|
+
@backend.clear
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
# (see Proxy#slice)
|
86
|
+
def slice(*keys, **options)
|
87
|
+
hash = @backend.read_multi(*keys)
|
88
|
+
if (expires = expires_value(options, nil)) != nil
|
89
|
+
hash.each do |key, value|
|
90
|
+
@backend.write(key, value, options.merge(expires_in: expires ? expires.seconds : nil))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
if options[:raw]
|
94
|
+
hash.each do |key, value|
|
95
|
+
hash[key] = value.to_s if value != nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
hash
|
99
|
+
end
|
100
|
+
|
101
|
+
# (see Proxy#values_at)
|
102
|
+
def values_at(*keys, **options)
|
103
|
+
hash = slice(*keys, **options)
|
104
|
+
keys.map { |key| hash[key] }
|
105
|
+
end
|
106
|
+
|
107
|
+
# (see Proxy#merge!)
|
108
|
+
def merge!(pairs, options = {})
|
109
|
+
if block_given?
|
110
|
+
existing = slice(*pairs.map { |k, _| k }, **options)
|
111
|
+
pairs = pairs.map do |key, new_value|
|
112
|
+
if existing.key?(key)
|
113
|
+
new_value = yield(key, existing[key], new_value)
|
114
|
+
end
|
115
|
+
|
116
|
+
[key, new_value]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
hash = Hash === pairs ? pairs : Hash[pairs.to_a]
|
121
|
+
expires = expires_value(options)
|
122
|
+
@backend.write_multi(hash, options.merge(expires_in: expires ? expires.seconds : nil))
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
def expires_value(options, default = @default_expires)
|
129
|
+
super.tap { options.delete(:expires) unless options.frozen? }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -4,61 +4,92 @@ module Moneta
|
|
4
4
|
module Adapters
|
5
5
|
# Cassandra backend
|
6
6
|
# @api public
|
7
|
-
# @author Potapov Sergey (aka Blake)
|
8
7
|
class Cassandra
|
9
8
|
include Defaults
|
10
9
|
include ExpiresSupport
|
11
10
|
|
12
11
|
attr_reader :backend
|
13
12
|
|
13
|
+
supports :each_key
|
14
|
+
|
14
15
|
# @param [Hash] options
|
15
16
|
# @option options [String] :keyspace ('moneta') Cassandra keyspace
|
16
|
-
# @option options [String] :
|
17
|
+
# @option options [String] :table ('moneta') Cassandra table
|
17
18
|
# @option options [String] :host ('127.0.0.1') Server host name
|
18
19
|
# @option options [Integer] :port (9160) Server port
|
19
20
|
# @option options [Integer] :expires Default expiration time
|
20
|
-
# @option options [
|
21
|
+
# @option options [String] :key_column ('key') Name of the key column
|
22
|
+
# @option options [String] :value_column ('value') Name of the value
|
23
|
+
# column
|
24
|
+
# @option options [String] :updated_column ('updated_at') Name of the
|
25
|
+
# column used to track last update
|
26
|
+
# @option options [String] :expired_column ('expired') Name of the column
|
27
|
+
# used to track expiry
|
28
|
+
# @option options [Symbol] :read_consistency (:all) Default read
|
29
|
+
# consistency
|
30
|
+
# @option options [Symbol] :write_consistency (:all) Default write
|
31
|
+
# consistency
|
32
|
+
# @option options [Proc, Boolean, Hash] :create_keyspace Provide a proc
|
33
|
+
# for creating the keyspace, or a Hash of options to use when creating
|
34
|
+
# it, or set to false to disable. The Proc will only be called if the
|
35
|
+
# keyspace does not already exist.
|
36
|
+
# @option options [::Cassandra::Cluster] :cluster Existing cluster to use
|
37
|
+
# @option options [::Cassandra::Session] :backend Existing session to use
|
21
38
|
# @option options Other options passed to `Cassandra#new`
|
22
39
|
def initialize(options = {})
|
23
40
|
self.default_expires = options.delete(:expires)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
begin
|
45
|
-
@backend.add_keyspace(ks_def)
|
46
|
-
rescue Exception => ex
|
47
|
-
warn "Moneta::Adapters::Cassandra - #{ex.message}"
|
48
|
-
end
|
49
|
-
break if @backend.keyspaces.include?(keyspace)
|
50
|
-
sleep 0.1
|
51
|
-
end
|
41
|
+
keyspace = options.delete(:keyspace) || 'moneta'
|
42
|
+
|
43
|
+
@table = (options.delete(:column_family) || 'moneta').to_sym
|
44
|
+
@key_column = options.delete(:key_column) || 'key'
|
45
|
+
@value_column = options.delete(:value_column) || 'value'
|
46
|
+
@updated_column = options.delete(:updated_column) || 'updated_at'
|
47
|
+
@expired_column = options.delete(:expired_column) || 'expired'
|
48
|
+
@read_consistency = options.delete(:read_consistency) || :all
|
49
|
+
@write_consistency = options.delete(:write_consistency) || :all
|
50
|
+
@create_keyspace = options.delete(:create_keyspace)
|
51
|
+
|
52
|
+
unless @backend = options.delete(:backend)
|
53
|
+
cluster = options.delete(:cluster) || (@own_cluster = ::Cassandra.cluster(options))
|
54
|
+
begin
|
55
|
+
@backend = cluster.connect(keyspace)
|
56
|
+
rescue ::Cassandra::Errors::InvalidError
|
57
|
+
@backend = cluster.connect
|
58
|
+
create_keyspace(keyspace)
|
59
|
+
@backend.execute("USE " + keyspace)
|
60
|
+
@backend
|
52
61
|
end
|
53
|
-
@backend.keyspace = keyspace
|
54
62
|
end
|
63
|
+
|
64
|
+
@backend.execute <<-CQL
|
65
|
+
CREATE TABLE IF NOT EXISTS #{@table} (
|
66
|
+
#{@key_column} blob,
|
67
|
+
#{@value_column} blob,
|
68
|
+
#{@updated_column} timeuuid,
|
69
|
+
#{@expired_column} boolean,
|
70
|
+
PRIMARY KEY (#{@key_column}, #{@updated_column})
|
71
|
+
)
|
72
|
+
CQL
|
73
|
+
|
74
|
+
prepare_statements
|
55
75
|
end
|
56
76
|
|
57
77
|
# (see Proxy#key?)
|
58
78
|
def key?(key, options = {})
|
59
|
-
|
60
|
-
|
79
|
+
rc, wc = consistency(options)
|
80
|
+
if (expires = expires_value(options, nil)) != nil
|
81
|
+
# Because Cassandra expires each value in a column, rather than the
|
82
|
+
# whole column, when we want to update the expiry we load the value
|
83
|
+
# and then re-set it in order to update the TTL.
|
84
|
+
return false unless
|
85
|
+
row = @backend.execute(@load, options.merge(consistency: rc, arguments: [key])).first and
|
86
|
+
row[@expired_column] != nil
|
87
|
+
@backend.execute(@update_expires, options.merge(consistency: wc, arguments: [
|
88
|
+
(expires || 0).to_i, timestamp, row[@value_column], key, row[@updated_column]
|
89
|
+
]))
|
61
90
|
true
|
91
|
+
elsif row = @backend.execute(@key, options.merge(consistency: rc, arguments: [key])).first
|
92
|
+
row[@expired_column] != nil
|
62
93
|
else
|
63
94
|
false
|
64
95
|
end
|
@@ -66,38 +97,253 @@ module Moneta
|
|
66
97
|
|
67
98
|
# (see Proxy#load)
|
68
99
|
def load(key, options = {})
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
100
|
+
rc, wc = consistency(options)
|
101
|
+
if row = @backend.execute(@load, options.merge(consistency: rc, arguments: [key])).first and row[@expired_column] != nil
|
102
|
+
if (expires = expires_value(options, nil)) != nil
|
103
|
+
@backend.execute(@update_expires, options.merge(consistency: wc, arguments: [
|
104
|
+
(expires || 0).to_i, timestamp, row[@value_column], key, row[@updated_column]
|
105
|
+
]))
|
106
|
+
end
|
107
|
+
row[@value_column]
|
73
108
|
end
|
74
109
|
end
|
75
110
|
|
76
111
|
# (see Proxy#store)
|
77
112
|
def store(key, value, options = {})
|
78
|
-
|
113
|
+
_, wc = consistency(options)
|
114
|
+
expires = expires_value(options)
|
115
|
+
t = timestamp
|
116
|
+
batch = @backend.batch do |batch|
|
117
|
+
batch.add(@store_delete, arguments: [t, key])
|
118
|
+
batch.add(@store, arguments: [key, value, (expires || 0).to_i, t + 1])
|
119
|
+
end
|
120
|
+
@backend.execute(batch, options.merge(consistency: wc))
|
79
121
|
value
|
80
122
|
end
|
81
123
|
|
82
124
|
# (see Proxy#delete)
|
83
125
|
def delete(key, options = {})
|
84
|
-
|
85
|
-
|
86
|
-
|
126
|
+
rc, wc = consistency(options)
|
127
|
+
result = @backend.execute(@delete_value, options.merge(consistency: rc, arguments: [key]))
|
128
|
+
if row = result.first and row[@expired_column] != nil
|
129
|
+
@backend.execute(@delete, options.merge(consistency: wc, arguments: [timestamp, key, row[@updated_column]]))
|
130
|
+
row[@value_column]
|
87
131
|
end
|
88
132
|
end
|
89
133
|
|
90
134
|
# (see Proxy#clear)
|
91
135
|
def clear(options = {})
|
92
|
-
@backend.
|
136
|
+
@backend.execute(@clear)
|
93
137
|
self
|
94
138
|
end
|
95
139
|
|
96
140
|
# (see Proxy#close)
|
97
141
|
def close
|
98
|
-
@backend.
|
142
|
+
@backend.close_async
|
143
|
+
@backend = nil
|
144
|
+
if @own_cluster
|
145
|
+
@own_cluster.close_async
|
146
|
+
@own_cluster = nil
|
147
|
+
end
|
99
148
|
nil
|
100
149
|
end
|
150
|
+
|
151
|
+
# (see Proxy#each_key)
|
152
|
+
def each_key
|
153
|
+
rc, _ = consistency
|
154
|
+
return enum_for(:each_key) unless block_given?
|
155
|
+
result = @backend.execute(@each_key, consistency: rc, page_size: 100)
|
156
|
+
loop do
|
157
|
+
result.each do |row|
|
158
|
+
next if row[@expired_column] == nil
|
159
|
+
yield row[@key_column]
|
160
|
+
end
|
161
|
+
|
162
|
+
break if result.last_page?
|
163
|
+
result = result.next_page
|
164
|
+
end
|
165
|
+
self
|
166
|
+
end
|
167
|
+
|
168
|
+
# (see Proxy#slice)
|
169
|
+
def slice(*keys, **options)
|
170
|
+
rc, wc = consistency(options)
|
171
|
+
result = @backend.execute(@slice, options.merge(consistency: rc, arguments: [keys]))
|
172
|
+
expires = expires_value(options, nil)
|
173
|
+
updated = [] if expires != nil
|
174
|
+
pairs = result.map do |row|
|
175
|
+
next if row[@expired_column] == nil
|
176
|
+
if expires != nil
|
177
|
+
updated << [row[@key_column], row[@value_column], row[@updated_column]]
|
178
|
+
end
|
179
|
+
[row[@key_column], row[@value_column]]
|
180
|
+
end.compact
|
181
|
+
|
182
|
+
if expires != nil && !updated.empty?
|
183
|
+
ttl = (expires || 0).to_i
|
184
|
+
t = timestamp
|
185
|
+
batch = @backend.batch do |batch|
|
186
|
+
updated.each do |key, value, updated|
|
187
|
+
batch.add(@update_expires, arguments: [ttl, t, value, key, updated])
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
@backend.execute(batch, options.merge(consistency: wc))
|
192
|
+
end
|
193
|
+
|
194
|
+
pairs
|
195
|
+
end
|
196
|
+
|
197
|
+
# (see Proxy#values_at)
|
198
|
+
def values_at(*keys, **options)
|
199
|
+
hash = Hash[slice(*keys, **options)]
|
200
|
+
keys.map { |key| hash[key] }
|
201
|
+
end
|
202
|
+
|
203
|
+
# (see Proxy#fetch_values)
|
204
|
+
def fetch_values(*keys, **options)
|
205
|
+
return values_at(*keys, **options) unless block_given?
|
206
|
+
hash = Hash[slice(*keys, **options)]
|
207
|
+
keys.map do |key|
|
208
|
+
if hash.key?(key)
|
209
|
+
hash[key]
|
210
|
+
else
|
211
|
+
yield key
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# (see Proxy#merge!)
|
217
|
+
def merge!(pairs, options = {})
|
218
|
+
keys = pairs.map { |k, _| k }.to_a
|
219
|
+
return self if keys.empty?
|
220
|
+
|
221
|
+
if block_given?
|
222
|
+
existing = Hash[slice(*keys, **options)]
|
223
|
+
pairs = pairs.map do |key, new_value|
|
224
|
+
if existing.key?(key)
|
225
|
+
[key, yield(key, existing[key], new_value)]
|
226
|
+
else
|
227
|
+
[key, new_value]
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
rc, wc = consistency(options)
|
233
|
+
expires = expires_value(options)
|
234
|
+
t = timestamp
|
235
|
+
batch = @backend.batch do |batch|
|
236
|
+
batch.add(@merge_delete, arguments: [t, keys])
|
237
|
+
pairs.each do |key, value|
|
238
|
+
batch.add(@store, arguments: [key, value, (expires || 0).to_i, t + 1])
|
239
|
+
end
|
240
|
+
end
|
241
|
+
@backend.execute(batch, options.merge(consistency: wc))
|
242
|
+
|
243
|
+
self
|
244
|
+
end
|
245
|
+
|
246
|
+
private
|
247
|
+
|
248
|
+
def timestamp
|
249
|
+
(Time.now.to_r * 1_000_000).to_i
|
250
|
+
end
|
251
|
+
|
252
|
+
def create_keyspace(keyspace)
|
253
|
+
options = {
|
254
|
+
replication: {
|
255
|
+
class: 'SimpleStrategy',
|
256
|
+
replication_factor: 1
|
257
|
+
}
|
258
|
+
}
|
259
|
+
|
260
|
+
case @create_keyspace
|
261
|
+
when Proc
|
262
|
+
return @create_keyspace.call(keyspace)
|
263
|
+
when false
|
264
|
+
return
|
265
|
+
when Hash
|
266
|
+
options.merge!(@create_keyspace)
|
267
|
+
end
|
268
|
+
|
269
|
+
# This is a bit hacky, but works. Options in Cassandra look like JSON,
|
270
|
+
# but use single quotes instead of double-quotes.
|
271
|
+
require 'multi_json'
|
272
|
+
option_str = options.map do |key, value|
|
273
|
+
key.to_s + ' = ' + MultiJson.dump(value).gsub('"', "'")
|
274
|
+
end.join(' AND ')
|
275
|
+
|
276
|
+
@backend.execute "CREATE KEYSPACE IF NOT EXISTS %s WITH %s" % [
|
277
|
+
keyspace,
|
278
|
+
option_str
|
279
|
+
]
|
280
|
+
rescue ::Cassandra::Errors::TimeoutError
|
281
|
+
tries ||= 0
|
282
|
+
if (tries += 1) <= 3; retry else raise end
|
283
|
+
end
|
284
|
+
|
285
|
+
def prepare_statements
|
286
|
+
@key = @backend.prepare(<<-CQL)
|
287
|
+
SELECT #{@updated_column}, #{@expired_column}
|
288
|
+
FROM #{@table} WHERE #{@key_column} = ?
|
289
|
+
LIMIT 1
|
290
|
+
CQL
|
291
|
+
@store_delete = @backend.prepare(<<-CQL)
|
292
|
+
DELETE FROM #{@table}
|
293
|
+
USING TIMESTAMP ?
|
294
|
+
WHERE #{@key_column} = ?
|
295
|
+
CQL
|
296
|
+
@store = @backend.prepare(<<-CQL)
|
297
|
+
INSERT INTO #{@table} (#{@key_column}, #{@value_column}, #{@updated_column}, #{@expired_column})
|
298
|
+
VALUES (?, ?, now(), false)
|
299
|
+
USING TTL ? AND TIMESTAMP ?
|
300
|
+
CQL
|
301
|
+
@load = @backend.prepare(<<-CQL)
|
302
|
+
SELECT #{@value_column}, #{@updated_column}, #{@expired_column}
|
303
|
+
FROM #{@table}
|
304
|
+
WHERE #{@key_column} = ?
|
305
|
+
LIMIT 1
|
306
|
+
CQL
|
307
|
+
@update_expires = @backend.prepare(<<-CQL)
|
308
|
+
UPDATE #{@table}
|
309
|
+
USING TTL ? AND TIMESTAMP ?
|
310
|
+
SET #{@value_column} = ?, #{@expired_column} = false
|
311
|
+
WHERE #{@key_column} = ? AND #{@updated_column} = ?
|
312
|
+
CQL
|
313
|
+
@clear = @backend.prepare("TRUNCATE #{@table}")
|
314
|
+
@delete_value = @backend.prepare(<<-CQL)
|
315
|
+
SELECT #{@value_column}, #{@updated_column}, #{@expired_column}
|
316
|
+
FROM #{@table}
|
317
|
+
WHERE #{@key_column} = ?
|
318
|
+
LIMIT 1
|
319
|
+
CQL
|
320
|
+
@delete = @backend.prepare(<<-CQL, idempotent: true)
|
321
|
+
DELETE FROM #{@table}
|
322
|
+
USING TIMESTAMP ?
|
323
|
+
WHERE #{@key_column} = ? AND #{@updated_column} = ?
|
324
|
+
CQL
|
325
|
+
@each_key = @backend.prepare(<<-CQL)
|
326
|
+
SELECT #{@key_column}, #{@expired_column}
|
327
|
+
FROM #{@table}
|
328
|
+
CQL
|
329
|
+
@slice = @backend.prepare(<<-CQL)
|
330
|
+
SELECT #{@key_column}, #{@value_column}, #{@updated_column}, #{@expired_column}
|
331
|
+
FROM #{@table}
|
332
|
+
WHERE #{@key_column} IN ?
|
333
|
+
CQL
|
334
|
+
@merge_delete = @backend.prepare(<<-CQL)
|
335
|
+
DELETE FROM #{@table}
|
336
|
+
USING TIMESTAMP ?
|
337
|
+
WHERE #{@key_column} IN ?
|
338
|
+
CQL
|
339
|
+
end
|
340
|
+
|
341
|
+
def consistency(options={})
|
342
|
+
[
|
343
|
+
options[:read_consistency] || @read_consistency,
|
344
|
+
options[:write_consistency] || @write_consistency
|
345
|
+
]
|
346
|
+
end
|
101
347
|
end
|
102
348
|
end
|
103
349
|
end
|