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
@@ -83,8 +83,17 @@ module Moneta
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def read
|
86
|
-
size = @socket.
|
87
|
-
|
86
|
+
size = @socket.
|
87
|
+
recv(4).tap do |bytes|
|
88
|
+
raise EOFError.new('failed to read size') unless bytes.bytesize == 4
|
89
|
+
end.
|
90
|
+
unpack('N').
|
91
|
+
first
|
92
|
+
|
93
|
+
result = Marshal.load(@socket.recv(size).tap do |bytes|
|
94
|
+
raise EOFError.new("Not enough bytes read") unless bytes.bytesize == size
|
95
|
+
end)
|
96
|
+
|
88
97
|
raise result if Exception === result
|
89
98
|
result
|
90
99
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'multi_json'
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
module Moneta
|
5
6
|
module Adapters
|
@@ -8,7 +9,7 @@ module Moneta
|
|
8
9
|
# You can store hashes directly using this adapter.
|
9
10
|
#
|
10
11
|
# @example Store hashes
|
11
|
-
# db = Moneta::Adapters::
|
12
|
+
# db = Moneta::Adapters::Couch.new
|
12
13
|
# db['key'] = {a: 1, b: 2}
|
13
14
|
#
|
14
15
|
# @api public
|
@@ -17,7 +18,7 @@ module Moneta
|
|
17
18
|
|
18
19
|
attr_reader :backend
|
19
20
|
|
20
|
-
supports :create
|
21
|
+
supports :create, :each_key
|
21
22
|
|
22
23
|
# @param [Hash] options
|
23
24
|
# @option options [String] :host ('127.0.0.1') Couch host
|
@@ -31,26 +32,33 @@ module Moneta
|
|
31
32
|
@type_field = options[:type_field] || 'type'
|
32
33
|
url = "http://#{options[:host] || '127.0.0.1'}:#{options[:port] || 5984}/#{options[:db] || 'moneta'}"
|
33
34
|
@backend = options[:backend] || ::Faraday.new(url: url)
|
35
|
+
@rev_cache = Moneta.build do
|
36
|
+
use :Lock
|
37
|
+
adapter :LRUHash
|
38
|
+
end
|
34
39
|
create_db
|
35
40
|
end
|
36
41
|
|
37
42
|
# (see Proxy#key?)
|
38
43
|
def key?(key, options = {})
|
39
|
-
@backend.head(key)
|
44
|
+
response = @backend.head(key)
|
45
|
+
update_rev_cache(key, response)
|
46
|
+
response.status == 200
|
40
47
|
end
|
41
48
|
|
42
49
|
# (see Proxy#load)
|
43
50
|
def load(key, options = {})
|
44
51
|
response = @backend.get(key)
|
52
|
+
update_rev_cache(key, response)
|
45
53
|
response.status == 200 ? body_to_value(response.body) : nil
|
46
54
|
end
|
47
55
|
|
48
56
|
# (see Proxy#store)
|
49
57
|
def store(key, value, options = {})
|
50
|
-
|
51
|
-
body = value_to_body(value, response.status == 200 && response['etag'][1..-2])
|
58
|
+
body = value_to_body(value, rev(key))
|
52
59
|
response = @backend.put(key, body, 'Content-Type' => 'application/json')
|
53
|
-
|
60
|
+
update_rev_cache(key, response)
|
61
|
+
raise "HTTP error #{response.status} (PUT /#{key})" unless response.status == 201
|
54
62
|
value
|
55
63
|
rescue
|
56
64
|
tries ||= 0
|
@@ -59,11 +67,13 @@ module Moneta
|
|
59
67
|
|
60
68
|
# (see Proxy#delete)
|
61
69
|
def delete(key, options = {})
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
70
|
+
clear_rev_cache(key)
|
71
|
+
get_response = @backend.get(key)
|
72
|
+
if get_response.status == 200
|
73
|
+
existing_rev = get_response['etag'][1..-2]
|
74
|
+
value = body_to_value(get_response.body)
|
75
|
+
delete_response = @backend.delete("#{key}?rev=#{existing_rev}")
|
76
|
+
raise "HTTP error #{response.status}" unless delete_response.status == 200
|
67
77
|
value
|
68
78
|
end
|
69
79
|
rescue
|
@@ -82,6 +92,7 @@ module Moneta
|
|
82
92
|
def create(key, value, options = {})
|
83
93
|
body = value_to_body(value, nil)
|
84
94
|
response = @backend.put(key, body, 'Content-Type' => 'application/json')
|
95
|
+
update_rev_cache(key, response)
|
85
96
|
case response.status
|
86
97
|
when 201
|
87
98
|
true
|
@@ -95,10 +106,99 @@ module Moneta
|
|
95
106
|
(tries += 1) < 10 ? retry : raise
|
96
107
|
end
|
97
108
|
|
109
|
+
# (see Proxy#each_key)
|
110
|
+
def each_key
|
111
|
+
return enum_for(:each_key) unless block_given?
|
112
|
+
|
113
|
+
skip = 0
|
114
|
+
limit = 1000
|
115
|
+
total_rows = 1
|
116
|
+
while total_rows > skip do
|
117
|
+
response = @backend.get("_all_docs?" + encode_query(limit: limit, skip: skip))
|
118
|
+
case response.status
|
119
|
+
when 200
|
120
|
+
result = MultiJson.load(response.body)
|
121
|
+
total_rows = result['total_rows']
|
122
|
+
skip += result['rows'].length
|
123
|
+
result['rows'].each do |row|
|
124
|
+
key = row['id']
|
125
|
+
@rev_cache[key] = row['value']['rev']
|
126
|
+
yield key
|
127
|
+
end
|
128
|
+
else
|
129
|
+
raise "HTTP error #{response.status}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
self
|
133
|
+
end
|
134
|
+
|
135
|
+
# (see Proxy#values_at)
|
136
|
+
def values_at(*keys, **options)
|
137
|
+
hash = Hash[slice(*keys, **options)]
|
138
|
+
keys.map { |key| hash[key] }
|
139
|
+
end
|
140
|
+
|
141
|
+
# (see Proxy#slice)
|
142
|
+
def slice(*keys, **options)
|
143
|
+
response = @backend.get('_all_docs?' + encode_query(keys: keys, include_docs: true))
|
144
|
+
raise "HTTP error #{response.status}" unless response.status == 200
|
145
|
+
docs = MultiJson.load(response.body)
|
146
|
+
docs["rows"].map do |row|
|
147
|
+
next unless row['doc']
|
148
|
+
[row['id'], doc_to_value(row['doc'])]
|
149
|
+
end.compact
|
150
|
+
end
|
151
|
+
|
152
|
+
# (see Proxy#merge!)
|
153
|
+
def merge!(pairs, options = {})
|
154
|
+
keys = pairs.map { |key, _| key }.to_a
|
155
|
+
cache_revs(*keys.reject { |key| @rev_cache[key] })
|
156
|
+
|
157
|
+
if block_given?
|
158
|
+
existing = Hash[slice(*keys, **options)]
|
159
|
+
pairs = pairs.map do |key, new_value|
|
160
|
+
[
|
161
|
+
key,
|
162
|
+
if existing.key?(key)
|
163
|
+
yield(key, existing[key], new_value)
|
164
|
+
else
|
165
|
+
new_value
|
166
|
+
end
|
167
|
+
]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
docs = pairs.map { |key, value| value_to_doc(value, @rev_cache[key], key) }.to_a
|
172
|
+
body = MultiJson.dump(docs: docs)
|
173
|
+
response = @backend.post('_bulk_docs', body, "Content-Type" => "application/json")
|
174
|
+
raise "HTTP error #{response.status}" unless response.status == 201
|
175
|
+
retries = []
|
176
|
+
MultiJson.load(response.body).each do |row|
|
177
|
+
if row['ok'] == true
|
178
|
+
@rev_cache[row['id']] = row['rev']
|
179
|
+
elsif row['error'] == 'conflict'
|
180
|
+
clear_rev_cache(row['id'])
|
181
|
+
retries << pairs.find { |key, _| key == row['id'] }
|
182
|
+
else
|
183
|
+
raise "Unrecognised response: #{row}"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Recursive call with all conflicts
|
188
|
+
if retries.empty?
|
189
|
+
self
|
190
|
+
else
|
191
|
+
merge!(retries, options)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
98
195
|
private
|
99
196
|
|
100
197
|
def body_to_value(body)
|
101
|
-
|
198
|
+
doc_to_value(MultiJson.load(body))
|
199
|
+
end
|
200
|
+
|
201
|
+
def doc_to_value(doc)
|
102
202
|
case doc[@type_field]
|
103
203
|
when 'Hash'
|
104
204
|
doc = doc.dup
|
@@ -111,24 +211,78 @@ module Moneta
|
|
111
211
|
end
|
112
212
|
end
|
113
213
|
|
214
|
+
def value_to_doc(value, rev, id = nil)
|
215
|
+
doc =
|
216
|
+
case value
|
217
|
+
when Hash
|
218
|
+
value.merge(@type_field => 'Hash')
|
219
|
+
when String
|
220
|
+
{ @value_field => value, @type_field => 'String' }
|
221
|
+
when Float, Integer
|
222
|
+
{ @value_field => value, @type_field => 'Number' }
|
223
|
+
else
|
224
|
+
raise ArgumentError, "Invalid value type: #{value.class}"
|
225
|
+
end
|
226
|
+
doc['_rev'] = rev if rev
|
227
|
+
doc['_id'] = id if id
|
228
|
+
doc
|
229
|
+
end
|
230
|
+
|
114
231
|
def value_to_body(value, rev)
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
232
|
+
MultiJson.dump(value_to_doc(value, rev))
|
233
|
+
end
|
234
|
+
|
235
|
+
def create_db
|
236
|
+
100.times do
|
237
|
+
response = @backend.put('', '')
|
238
|
+
case response.status
|
239
|
+
when 201
|
240
|
+
break
|
241
|
+
when 412
|
242
|
+
# Make sure the database really does exist
|
243
|
+
break if @backend.head('').status == 200
|
244
|
+
else
|
245
|
+
raise "HTTP error #{response.status}"
|
246
|
+
end
|
247
|
+
|
248
|
+
# Wait before trying again
|
249
|
+
sleep 1
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def cache_revs(*keys)
|
254
|
+
response = @backend.get('_all_docs?' + encode_query(keys: keys))
|
255
|
+
raise "HTTP error #{response.status}" unless response.status == 200
|
256
|
+
docs = MultiJson.load(response.body)
|
257
|
+
docs['rows'].each do |row|
|
258
|
+
next unless row['value']
|
259
|
+
@rev_cache[row['id']] = row['value']['rev']
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def update_rev_cache(key, response)
|
264
|
+
case response.status
|
265
|
+
when 200, 201
|
266
|
+
@rev_cache[key] = response['etag'][1..-2]
|
122
267
|
else
|
123
|
-
|
268
|
+
clear_rev_cache(key)
|
269
|
+
nil
|
124
270
|
end
|
125
|
-
doc['_rev'] = rev if rev
|
126
|
-
MultiJson.dump(doc)
|
127
271
|
end
|
128
272
|
|
129
|
-
def
|
130
|
-
|
131
|
-
|
273
|
+
def clear_rev_cache(key)
|
274
|
+
@rev_cache.delete(key)
|
275
|
+
end
|
276
|
+
|
277
|
+
def rev(key)
|
278
|
+
@rev_cache[key] || (
|
279
|
+
response = @backend.head(key) and
|
280
|
+
update_rev_cache(key, response)).tap do |rev|
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
def encode_query(query)
|
285
|
+
URI.encode_www_form(query.map { |key, value| [key, MultiJson.dump(value)] })
|
132
286
|
end
|
133
287
|
end
|
134
288
|
end
|
@@ -4,7 +4,13 @@ module Moneta
|
|
4
4
|
module Adapters
|
5
5
|
# Daybreak backend
|
6
6
|
# @api public
|
7
|
-
class Daybreak
|
7
|
+
class Daybreak
|
8
|
+
include Defaults
|
9
|
+
include DBMAdapter
|
10
|
+
include IncrementSupport
|
11
|
+
include CreateSupport
|
12
|
+
include EachKeySupport
|
13
|
+
|
8
14
|
# @param [Hash] options
|
9
15
|
# @option options [String] :file Database file
|
10
16
|
# @option options [::Daybreak] :backend Use existing backend instance
|
@@ -39,9 +45,20 @@ module Moneta
|
|
39
45
|
@backend.lock { super }
|
40
46
|
end
|
41
47
|
|
42
|
-
# (see Proxy#
|
43
|
-
def
|
44
|
-
|
48
|
+
# (see Proxy#merge!)
|
49
|
+
def merge!(pairs, options = {})
|
50
|
+
if block_given?
|
51
|
+
@backend.lock do
|
52
|
+
@backend.update(pairs.map do |key, new_value|
|
53
|
+
new_value = yield(key, load(key), new_value) if key?(key)
|
54
|
+
[key, new_value]
|
55
|
+
end)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
@backend.update(pairs)
|
59
|
+
end
|
60
|
+
|
61
|
+
self
|
45
62
|
end
|
46
63
|
end
|
47
64
|
end
|
data/lib/moneta/adapters/dbm.rb
CHANGED
@@ -4,7 +4,13 @@ module Moneta
|
|
4
4
|
module Adapters
|
5
5
|
# DBM backend (Berkeley DB)
|
6
6
|
# @api public
|
7
|
-
class DBM
|
7
|
+
class DBM
|
8
|
+
include Defaults
|
9
|
+
include DBMAdapter
|
10
|
+
include IncrementSupport
|
11
|
+
include CreateSupport
|
12
|
+
include EachKeySupport
|
13
|
+
|
8
14
|
# @param [Hash] options
|
9
15
|
# @option options [String] :file Database file
|
10
16
|
# @option options [::DBM] :backend Use existing backend instance
|
@@ -15,12 +21,6 @@ module Moneta
|
|
15
21
|
::DBM.new(options[:file])
|
16
22
|
end
|
17
23
|
end
|
18
|
-
|
19
|
-
# (see Proxy#close)
|
20
|
-
def close
|
21
|
-
@backend.close
|
22
|
-
nil
|
23
|
-
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/moneta/adapters/file.rb
CHANGED
@@ -6,7 +6,7 @@ module Moneta
|
|
6
6
|
# @api public
|
7
7
|
class File
|
8
8
|
include Defaults
|
9
|
-
supports :create, :increment
|
9
|
+
supports :create, :increment, :each_key
|
10
10
|
|
11
11
|
# @param [Hash] options
|
12
12
|
# @option options [String] :dir Directory where files will be stored
|
@@ -21,6 +21,16 @@ module Moneta
|
|
21
21
|
::File.exist?(store_path(key))
|
22
22
|
end
|
23
23
|
|
24
|
+
# (see Proxy#each_key)
|
25
|
+
def each_key(&block)
|
26
|
+
entries = ::Dir.entries(@dir).reject { |k| ::File.directory?(::File.join(@dir, k)) }
|
27
|
+
|
28
|
+
return enum_for(:each_key) { ::Dir.entries(@dir).length - 2 } unless block_given?
|
29
|
+
|
30
|
+
entries.each { |k| yield(k) }
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
24
34
|
# (see Proxy#load)
|
25
35
|
def load(key, options = {})
|
26
36
|
::File.read(store_path(key), mode: 'rb')
|
data/lib/moneta/adapters/gdbm.rb
CHANGED
@@ -4,7 +4,13 @@ module Moneta
|
|
4
4
|
module Adapters
|
5
5
|
# GDBM backend
|
6
6
|
# @api public
|
7
|
-
class GDBM
|
7
|
+
class GDBM
|
8
|
+
include Defaults
|
9
|
+
include DBMAdapter
|
10
|
+
include IncrementSupport
|
11
|
+
include CreateSupport
|
12
|
+
include EachKeySupport
|
13
|
+
|
8
14
|
# @param [Hash] options
|
9
15
|
# @option options [String] :file Database file
|
10
16
|
# @option options [::GDBM] :backend Use existing backend instance
|
@@ -15,12 +21,6 @@ module Moneta
|
|
15
21
|
::GDBM.new(options[:file])
|
16
22
|
end
|
17
23
|
end
|
18
|
-
|
19
|
-
# (see Proxy#close)
|
20
|
-
def close
|
21
|
-
@backend.close
|
22
|
-
nil
|
23
|
-
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -4,7 +4,12 @@ module Moneta
|
|
4
4
|
module Adapters
|
5
5
|
# KyotoCabinet backend
|
6
6
|
# @api public
|
7
|
-
class KyotoCabinet
|
7
|
+
class KyotoCabinet
|
8
|
+
include Defaults
|
9
|
+
include HashAdapter
|
10
|
+
|
11
|
+
supports :each_key, :increment, :create
|
12
|
+
|
8
13
|
# @param [Hash] options
|
9
14
|
# @option options [String] :file Database file
|
10
15
|
# @option options [::KyotoCabinet::DB] :backend Use existing backend instance
|
@@ -39,6 +44,66 @@ module Moneta
|
|
39
44
|
@backend.close
|
40
45
|
nil
|
41
46
|
end
|
47
|
+
|
48
|
+
# (see Proxy#each_key)
|
49
|
+
def each_key
|
50
|
+
return enum_for(:each_key) { @backend.count } unless block_given?
|
51
|
+
@backend.each_key{ |arr| yield arr[0] }
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
# (see Proxy#increment)
|
56
|
+
def increment(key, amount = 1, options = {})
|
57
|
+
ret = nil
|
58
|
+
success = @backend.accept(key) do |key, value|
|
59
|
+
if value
|
60
|
+
ret = Integer(value) + amount
|
61
|
+
else
|
62
|
+
ret = amount
|
63
|
+
end
|
64
|
+
ret.to_s
|
65
|
+
end
|
66
|
+
|
67
|
+
raise @backend.error unless success
|
68
|
+
ret
|
69
|
+
end
|
70
|
+
|
71
|
+
# (see Proxy#slice)
|
72
|
+
def slice(*keys, atomic: true, **options)
|
73
|
+
@backend.get_bulk(keys, atomic)
|
74
|
+
end
|
75
|
+
|
76
|
+
# (see Proxy#values_at)
|
77
|
+
def values_at(*keys, **options)
|
78
|
+
hash = slice(*keys, **options)
|
79
|
+
keys.map { |key| hash[key] }
|
80
|
+
end
|
81
|
+
|
82
|
+
# (see Proxy#merge!)
|
83
|
+
def merge!(pairs, options = {})
|
84
|
+
hard = options.key?(:hard) ? options[:hard] : false
|
85
|
+
atomic = options.key?(:atomic) ? options[:atomic] : true
|
86
|
+
|
87
|
+
success =
|
88
|
+
if block_given?
|
89
|
+
@backend.transaction(hard) do
|
90
|
+
existing = slice(*pairs.map { |k, _| k }, **options)
|
91
|
+
pairs = pairs.map do |key, new_value|
|
92
|
+
if existing.key?(key)
|
93
|
+
[key, yield(key, existing[key], new_value)]
|
94
|
+
else
|
95
|
+
[key, new_value]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
@backend.set_bulk(pairs.to_h, atomic) >= 0
|
99
|
+
end
|
100
|
+
else
|
101
|
+
@backend.set_bulk(pairs.to_h, atomic) >= 0
|
102
|
+
end
|
103
|
+
|
104
|
+
raise @backend.error unless success
|
105
|
+
self
|
106
|
+
end
|
42
107
|
end
|
43
108
|
end
|
44
109
|
end
|